Array operator.
Syntax |
Description |
---|---|
x = 2 : 10; |
x will be an array of numbers that start at 2 and increase by 1 for each consecutive number. The last entry will be <= 10. x will equal 2,3,...,9,10. |
x = 6 : -1.5 : 2; |
x will be the array were the first element is 6, and consecutive elements decrease by 1.5. All elements will be >=2. In this example, the array will be [6, 4.5, 3]. |
B=A(:, 2) |
B will be the array containing all the elements from the second dimension of A. |
Examples
Create a vector, then access a portion of that matrix in reverse order with the : operator.
a=l:5; # a will be vector (1, 2, 3, 4, 5) ?b=a(4:-1:2); # b will be vector (4, 3, 2)
Create a matrix, then access all the element of a dimension of that matrix with the : operator:
a=[1,2,3;4,5,6]; ?b=a(:, 1); # b will be vector (1, 4)
See Also