Matlab - WordPress.com

advertisement
1
NET 222: COMMUNICATIONS AND
NETWORKS FUNDAMENTALS
(PRACTICAL PART)
Networks and
Communication
Department
Tutorial 2 : Matlab - Getting Started
Lecture Contents
2

Getting Started.
 The
MATLAB Desktop.
 Command window.
 Command History window.
 Current Folder window.
 Workspace window.
 Matlab menu bar.
Networks and Communication Department
Matrix Laboratory
3



Matlab = Matrix Laboratory
A software environment for interactive numerical computations
Examples:









Matrix computations and linear algebra
Solving nonlinear equations
Numerical solution of differential equations
Mathematical optimization
Statistics and data analysis
Signal processing
Modelling of dynamical systems
Solving partial differential equations
Simulation of engineering systems
Networks and Communication Department
MATLAB Toolboxes
4

MATLAB has a number of add-on software modules,
called toolboxes, that perform more specialized
computations.

Signal & Image Processing
Signal Processing- Image Processing Communications –
System Identification - Wavelet Filter Design

Control Design
Control System - Fuzzy Logic - Robust Control - μ-Analysis
and Synthesis - LMI Control Model Predictive Control
More than 60 toolboxes!
Networks and Communication Department
Simulink
5

Simulink - a package for modeling dynamic
systems.
Networks and Communication Department
Simulink (Cont.)
6

Analyzing results:
Networks and Communication Department
Getting Started.
7



MATLAB offers engineers, scientists, and
mathematicians an intuitive language for
expressing problems and their solutions
mathematically and graphically.
It integrates computation, visualization, and
programming in a flexible, open environment.
Complex numeric and symbolic problems can be
solved in a fraction of the time required with
other languages such as C, Fortran, or Java.
Networks and Communication Department
The MATLAB Desktop
8


MATLAB has an extensive graphical user
interface. When MATLAB starts, the main MATLAB
window appears.
The Desktop menu controls the layout and
appearance of the windows and gives you a list
of the windows you can use.
Networks and Communication Department
9
Networks and Communication Department
10
The MATLAB environment is command oriented
Networks and Communication Department
The first four appear by default, the first time you
use MATLAB.
11
Networks and Communication Department
12
The Start button in the bottom left corner of the MATLAB
Desktop brings up demos, tools, and other windows.
Networks and Communication Department
13
All MATLAB windows are docked in the default desktop,
which means that they are tiled on the main MATLAB
window.
Docked
window
Undocked
window
Networks and Communication Department
Command window
14
MATLAB expressions and
statements are evaluated as
you type them in the
Command Window, and
results of the computation
are displayed there too.
Networks and Communication Department
Command window
15



MATLAB expressions and statements are evaluated
as you type them in the Command Window, and
results of the computation are displayed there too.
Expressions and statements are also used in M-files
(see it later).
They are usually of the form:
or simply:
Networks and Communication Department
Command window (Cont.)
16



Expressions are usually composed from operators,
functions, and variable names.
Evaluation of the expression produces a matrix (or
other data type), which is then displayed on the
screen or assigned to a variable for future use.
If the variable name and = sign are omitted, a
variable ans (for answer) is automatically created
to which the result is assigned.
Networks and Communication Department
Command window (Cont.)
17



A statement is normally terminated at the end of
the line. However, a statement can be continued to
the next line with three periods (...) at the end of the
line.
Several statements can be placed on a single line
separated by commas or semicolons.
MATLAB is case-sensitive in the names of commands,
functions, and variables, so A and a are two
different variables.
Networks and Communication Department
Command window (Cont.)
18


A comma or blank separates the elements within a
row of a matrix (sometimes a comma is necessary to
split the expressions, because a blank can be
ambiguous).
A semicolon ends a row.
Networks and Communication Department
Command window (Cont.)
19



You can save the Command Window dialog with the
diary command:
This causes what appears subsequently in the Command
Window to be written to the named file (if the filename
is omitted, it is written to a default file named diary)
until you type the command diary off; the command
diary on causes writing to the file to resume.
When finished, you can edit the file as desired and
print it out.
Networks and Communication Department
Command window (Cont.)
20


Tab completion is another helpful shortcut. It works
in both the Command Window and the Editor.
Start typing a command name, a variable name, or
a filename. Before you type it all in, hit the tab key.
Try typing z then a tab. A list of all the functions
and variables that start with z will pop up. Select
one from the list, or keep typing to narrow down the
selection.
Networks and Communication Department
Command window (Cont.)
21
You can clear the Command Window with the clc
command or with Edit > Clear Command Window.

Networks and Communication Department
Command History window
22
This window lists the commands
typed in so far. You can re-execute
one more commands from this
window by double-clicking or
dragging the command(s) into the
Command Window.
Networks and Communication Department
Current Folder window
23
The Current Folder window displays a list of the files in
your current folder. The name of this folder also appears at
the top of the main MATLAB window, in the MATLAB Toolbar.
Your current folder is the first place MATLAB
looks for your M-files, and for workspace (.mat) files
containing data that you load and save.
MATLAB also looks in all the folders in your MATLAB path.
Folders that are not on your MATLAB path
are shown in gray.
Networks and Communication Department
Current Folder window (Cont.)
24
The commands:
pwd
returns the name of the current folder.
cd
changes the current folder.
dir
lists the contents of the current folder,
what
lists only the MATLAB-specific files in the
folder grouped by file type.
delete and type can be used to delete a file and
display a file in the Command
Window, respectively.

Networks and Communication Department
Workspace window
25
The Workspace window lists
variables that you have either
entered or computed in your
MATLAB session.
Networks and Communication Department
Workspace window (Cont.)
26


All the matrices and other variables that you create,
except those internal to M-files, are shown in your
Workspace window.
Double-clicking on a variable in the Workspace
window pulls up the Variable Editor.
Networks and Communication Department
Workspace window (Cont.)
27
The command:
whos

lists the variables currently in the
workspace.
clear variablename clear a variable or a function
from the workspace.
(or by right-clicking the variable in the
Workspace window and selecting Delete)
clear
clears all variables from the
workspace.
Networks and Communication Department
Workspace window (Cont.)
28


When you log out or exit MATLAB, all variables are
lost. However, invoking the command save before
exiting writes all variables to a binary file named
matlab.mat in the current folder.
When you later reenter MATLAB, the command load
restores the workspace to its former state.
Networks and Communication Department
Matlab menu bar
29
Networks and Communication Department
Matlab menu bar(Cont.)
30
Networks and Communication Department
Matlab menu bar (Cont.)
31
Networks and Communication Department
Matlab menu bar (Cont.)
32
Networks and Communication Department
Matlab menu bar (Cont.)
33
Networks and Communication Department
Matlab menu bar (Cont.)
34
Networks and Communication Department
Matlab menu bar (Cont.)
35
Networks and Communication Department
Some Useful MATLAB commands
36
Networks and Communication Department
Math
37

MATLAB can do simple math just as a calculator.
Networks and Communication Department
Interactive Calculations
38


Matlab is interactive, no need to declare variables.
Most elementary functions and constants are
already defined.
Networks and Communication Department
Functions
39


MATLAB has many built-in functions.
Some math functions are:
Networks and Communication Department
The Help System
40
Networks and Communication Department
The help system example
41
Networks and Communication Department
MATLAB Variable Names
42



Variable names ARE case sensitive
Variable names can contain up to 63 characters (as of
MATLAB 6.5 and newer)
Variable names must start with a letter followed by letters,
digits, and underscores.
Networks and Communication Department
MATLAB Special Variables
43
Networks and Communication Department
MATLAB Math & Assignment Operators
44
Networks and Communication Department
45
The End
Any Questions ?
Networks and Communication Department
Download