Single Index

If a matrix A is a row vector or a column vector, then A[k] refers to the $ k$th element of A. The index k is a number between 1 and the length of the vector. Note that 0 is not a valid index value.
>>  A = [3, 5, -2, 7, 0.9];
>>  A[3]
    -2
The index itself can be vector such that a bunch of the elements of A are referenced.
>>  A = [3, 5, -2, 7, 0.9];
>>  A[[1, 3, 5]]
    3  -2   0.9
>> A[1:3]
    3   5    -2
>> A[1 : 2 : 5]   // 1 : 2 : 5 is the same as [1, 3, 5]
    3  -2   0.9
The dollar sign $ when used as an index, is the largest value of the index, therefore A[$] is the last element of A.
>>  A = [3, 5, -2, 7, 0.9];
>>  A[$]
    0.9
>>  A[3:$]
    -2  7  0.9

If matrix A is not a vector, then the element referred to by A[k] is the k-th element of the row vector obtained by horizontally joining all the rows of A.

>> A = [1,4, 9; 2, 3, 5; -2, 5, 10]
   1   4    9
   2   3    5
  -2   5   10
>> A[5]
   3
>> A[9]
   10



oz 2009-12-22