Colon Notation
The colon(:) is one of the most useful operator in MATLAB. It is used to create vectors, subscript arrays, and specify for iterations.
If you want to create a row vector, containing integers from 1 to 10, you write:
1:10
MATLAB executes the statement and returns a row vector containing the integers from 1 to 10:
ans =
1 2 3 4 5 6 7 8 9 10
If you want to specify an increment value other than one, for example:
100: -5: 50
MATLAB executes the statement and returns the following result:
ans =
100 95 90 85 80 75 70 65 60 55 50
Let us take another example:
0:pi/8:pi
MATLAB executes the statement and returns the following result:
ans =
Columns 1 through 7
0 0.3927 0.7854 1.1781 1.5708 1.9635 2.3562
Columns 8 through 9
2.7489 3.1416
No comments:
Post a Comment