Digital Signal Processing Reference
In-Depth Information
2.1
Working with Variables
A common programming mistake is to use a variable without declaring it rst. This
is not a problem in MATLAB. In fact, MATLAB is very exible about variables
and data types. If an undened variable is assigned a value, for example:
a = 1;
MATLAB will assume that the variable a should be created, and that the value 1
should be stored in it. If the variable already exists, then it will have the number 1
replace its previous value.
This works with scalars, vectors, and matrices. The numbers stored in variables
can be integers (e.g., 3), oating-points (e.g., 3.1), or even complex (e.g., 3:1+5:2j).
a = 3;
b = 3.1;
c = 3.1+5.2j;
A semicolon \;" is often put at the end of a command. This has the eect of
suppressing the output of the resulting values. Leaving o the semicolon does not
aect the program, just what is printed to the screen, though printing to the screen
can make a program run slowly. If a variable name is typed on a line by itself,
then the value(s) stored for that variable will be printed. This also works inside a
function or a program. A variable on a line by itself (without a semicolon) will be
displayed.
>> a
a =
3
>> b
b =
3.1000
>> c
Search WWH ::




Custom Search