Digital Signal Processing Reference
In-Depth Information
»
x.^3
% Exponentiation: power of 3 for each element in matrix x
ans ¼
18
27 64
»
y.^x
% Exponentiation: each element in y has a power
% specified by a corresponding element in matrix x
ans
¼
-4 9
-8 1
»
x
[0 1 2 3 4 5 6]
% Initialize a row vector
¼
x
0123456
»
y ¼ x.*x-2*x
% Use array element product to compute a quadratic function
y 0 -1 0 3 8 15 24
»
z ¼ [1 3]'
% Initialize a column vector
z 1
3
»
w ¼ x\z
% Invert matrix x, then multiply it by the column vector z
w 1
0
A.2 MATLAB ARRAYS AND INDEXING
Let us look at the syntax to create an array as follows:
Basic syntax: x [ begin: step: end
An array x is created with the first element value of begin. The value increases by a value of step
for the next element in the array and stops when the next stepped value is beyond the specified end
value of end. In simulation, we may use this operation to create the sample indexes or array of time
instants for digital signals. The begin,
step, and end can be assigned to integers or floating-point
numbers.
The following examples are given for illustrations:
»
n ¼ 1:3:8
% Create a vector n ¼ [1 4 7]
n 147
»
m ¼ 9:-1:2
% Create a vector m ¼ [98765432]
m 98765432
Search WWH ::




Custom Search