Element Referencing

Any expression that evaluates to a matrix can have its elements referenced. The simplest case occurs when a matrix has been created and assigned to a variable. One can reference single elements, or one can reference full or partial rows and/or columns of a matrix. Element referencing is performed via the `[ ]' operators, using the `;' to delimit row and column specifications, and the `,' to delimit individual row or column specifications.

To reference a single element:

> a = [1,2,3; 4,5,6; 7,8,9];
> a [ 2 ; 3 ]
        6

To reference an entire row, or column:

> a [ 2 ; ]
        4          5          6  
> a [ ; 3 ]
        3  
        6  
        9

To reference a sub-matrix:

> a [ 2,3 ; 1,2 ]
        4          5  
        7          8

As stated previously, any expression that evaluates to a matrix can have its elements referenced. A very common example is getting the row or column dimension of a matrix:

> size (a)[1]
        3

In the previous example the function size returns a two-element matrix, from which we extract the 1st element (the value of the row dimension). Note that we referenced the return value (a matrix) as if it were a vector. Referencing matrices in ``vector-fashion'' is allowed with all matrices. When vector-indexing is used, the matrix elements are referenced in column order. As with matrix indexing, a combination of vector elements can be referenced:

> a[3]
        7
> a[3,4,9]
        7          2          9