The matrix indexing operator is []. For example, the second element of x is x[2] and the element of A at row 3 and column 5 is A[3,5].
A(x) is evaluated as A * x. That is, matrix A is used as a linear function (In order for A(x) to work, the number of rows of x should match the number of columns of A). A matrix is a function and can be used anywhere a function is expected.
Dense matrices are stored in row major order. Thus, if
A is an
matrix, A[j, k] is equivalent to
A[j * n + k].
The last element of A is A[$], not A[end].
The last element on the third row of A is A[3, $], not A[3, end].
rand(n), zeros(n), and ones(n) return
matrices in stead of
square matrices. To obtain square
matrices, one has to use calls like rand(n, n)
Dense matrices are stored in row major order, as opposed to the column major order used in Matlab. This means that each row of a matrix is usually stored in a contiguous memory block, and the rows are stored one after another.
Row major and column major are equivalent when elements of A are accessed by using two indices like in A[i, j]. However, expression with a single index behaves differently in row major and column major. For example, if A is a matrix of 5 rows and 5 columns, then A[1], ...,A[5] are the five elements in the first row, while A[6], ..., A[10] refer to the five elements in the second row.
Semicolons and backslashes can be used in indexing expressions. For examples
oz 2009-12-22