Signals and Systems - Electrical Engineering

(avery) #1

32 C H A P T E R 0: From the Ground Up!


giving as expected the first to the third entries of the column vectory:
ans =
1
2
3

The following will give the third to the first entry in the row vectorx(notice the difference in the two
outputs; as expected the values ofyare given in a column, while the requested entries ofxare given
in a row).
x(3:-1:1) % displays entries x(3) x(2) x(1)

Thus,
ans =
3 2 1

Matrices are constructed as an concatenation of rows (or columns):
A = [ 1 2; 3 4; 5 6] % matrix A with rows [1 2], [3 4] and [5 6]
A =
1 2
3 4
5 6

To create a vector corresponding to a sequence of numbers (in this case integers) there are different
approaches, as follows:
n = 0:10 % vector with entries 0 to 10 increased by 1

This approach gives the following as output:
n =
Columns 1 through 10
0 1 2 3 4 5 6 7 8 9
Column 11
10

which is the same as the command
n = [0:10]

If we wish the increment different from 1 (default value), then we indicate it as in the following:
n1 = 0:2:10 % vector with entries from 0 to 10 increased by 2

which gives
n1 =
0 2 4 6 8 10

We can combine the above vectors into one as follows:
nn1 = [n n1] % combination of vectors
Free download pdf