Matrix

Matrix element and submatrix indexing operator []. The syntax is
A[index]
where A is a matrix of any numerical type. The index can have a single part, or two parts separated by a comma, or two parts separated by a semicolon, or more (3+) parts separated by commas.

  1. A single index. The index must be a matrix of positive integers. The value of the indexing expression is a matrix.
  2. Two indices separated by a comma. This will extract a square block of the matrix, except when the first index is a slash \, where the result is one or more diagonals of the matrix.
  3. Two indices separated by a semicolon.

    The value of the indexing expression is a column vector

  4. Three or more indices separated by commas. This can only be used on multi-dimensional matrix.

Colon Operator for creating evenly spaced vector

If a and b are two real scalar, a : b returns a row vector of numbers a, a+1, a+2, up to b, or the largest number a+n such that a+n <= b. If a<b+1, then a : b returns empty matrix.

>> v = 1 : 5
   1  2  3  4  5
>> v = 1.2 : 5.3
   1.2  2.2  3.2  4.2  5.2
>> v = 3 : -1
   []

If a<b are two real numbers, and h>0, then a : h : b returns a row vector of numbers a, a+h, a+2h, up to b, or the largest number a+nh such that a+nh <= b.

If a>b, and h<0, then a : h : b returns a row vector of numbers a, a+h, a+2h, down to b, or the smallest number a+nh such that a+nh> b. a : b returns empty matrix.

>> v = 1 : 2 : 10
   1  3  5  7  9
>> v = 1.2 : -1 : -5
   1.2   -0.2  -1.2  -2.2  -3.2  -4.2

oz 2009-12-22