$ stands for the largest index

In an index expression, the dollar sign $ stands for the largest possible value of the index. Suppose that A is an matrix. Then in the single-part index expression, the value of $ is the size of the matrix, that is, . Then A[$] returns A[m * n], the last element of A, and . A[$-1] returns A[m * n - 1], the second last element of A.

If $ appears in the row index of a two-part index expression, its value is m, the number of rows of the matrix; if it appears in the column index, its value is n, the number of columns of the matrix. Therefore, A[$, 2] returns the element at the last row and the second column, and A[1, $] returns the element at the first row and last column.

The dollar sign can participate in arithmetic operations. For example, A[$-2] gives the third last element of A; and A[1 : $, $ - 2] returns the second last column of A. Note that the two $'s have different values in this expression.

oz 2009-12-22