or simply
expression
Since MATLAB supports long variable names (up to 19 characters, start with a letter,
followed by letters, or digits, or underscores), we should take advantage of this feature
to give variables descriptive names.
The default operations in MATLAB are matrix (including vector and scalar) opera-
tions. The arithmetic operations between two scalars (1Â1 matrix) a and b are: a b
(addition), a À b (subtraction), a * b (multiplication), a/b (division), and a^b (a
b
). An
array operation is performed element-by-element. Suppose A and B vectors are row
vectors with the same number of elements. To generate a new row vector C with values
that are the operations of corresponding values in A and B element-by-element, we use
A B, AÀB, A.*B, A./B, and A.^B. For example,
x [1, 2, 3]; y [4, 5, 6];
then
z x.*y
results in
z 4 10 18
A period preceding an operator indicates an array or element-by-element operation.
For addition and subtraction, array operation and scalar operation are the same. Array
(element-by-element) operations apply not only to operations between two vectors of
the same size, but also to operations between a scalar and vector. For example, every
element in a vector A can be multiplied by a scalar b in MATLAB as B b*A or
B b.*A. In general, when `point' is used with another arithmetic operator, it modifies
that operator's usual matrix definition to a pointwise one.
Six relational operators: < (less than), <= (less than or equal), > (greater than), >=
(greater than or equal), == (equal), and ~= (not equal), are available for comparing two
matrices of equal dimensions. MATLAB compares the pairs of corresponding elements.
The result is a matrix of ones and zeros, with one representing `true' and zero represent-
ing `false.' In addition, the operators & (AND), | (OR), ~ (NOT), and xor (exclusive
OR) are the logical operators. These operators are particularly useful in if statements.
For example,
if a > b
do something
end
The colon operator `;' is useful for creating index arrays and creating vectors of
evenly spaced values. The index range can be generated using a start (initial value), a
skip (increment), and an end (final value). Therefore, a regularly spaced vector of
numbers is obtained by means of
n [start:skip:end]
Note that no brackets are required if a vector is generated this way. However, brackets
are required to force the concatenation of the two vectors. Without the skip para-
meter, the default increment is 1. For example,
458
APPENDIX B: INTRODUCTION OF MATLAB FOR DSP APPLICATIONS