Digital Signal Processing Reference
In-Depth Information
»
sum(x)
% Call MATLAB function sum
ans
¼
3.5000 8.5000 11.5000
% Display the results
»
MATLAB can be used like a calculator to work with numbers, variables, and expressions in the
command window. The following are basic syntax examples:
»
sin(pi/4)
ans
¼
0.7071
»
pi*4
ans
¼
12.5664
In MATLAB, variable names can store values, vectors and matrices. See the following
examples.
» x
¼
cos(pi/8)
x
0.9239
» y
¼
sqrt(x)-2^2
y
-3.0388
» z
¼
[1 -2 1 2]
z
1-212
» zz
¼
[1 2 3; 4 5 6]
zz
123
456
Complex numbers are natural in MATLAB. See the following examples.
»
z
3+4i
% Complex number
¼
z
3.0000 + 4.0000i
»
conj(z)
% Complex conjugate of z
ans
¼
3.0000 - 4.0000i
»
abs(z)
% Magnitude of z
ans
¼
5
»
angle(z)
% Angle of z (radians)
ans
¼
Search WWH ::
Custom Search