Using the C Math Library | ![]() ![]() |
Indexing Functions
An array subscript consists of one or more indices passed as mxArray *
arguments to one of the indexing functions. For example, the two-dimensional indexing expression
mlfIndexRef(A, "(?,?)", mlfScalar(3), mlfScalar(1))
applies the subscript (3,1)
to A
and returns the element at row three, column one. mlfIndexRef(A, "(?)", mlfScalar(9))
, a one-dimensional indexing expression, returns the ninth element of array A
.
Note The indexing functions follow the MATLAB convention for array indices: indices begin at one rather than zero. |
Both standard indexing and cell array indexing take numeric arguments, one argument for each dimension of the array being indexed into. Structure indexing uses only the name of the structure field.
The indexing functions in the MATLAB C Math Library support N-dimensional standard, cell array, and structure indexing.
An index mxArray
argument can contain a scalar, vector, matrix, or the result from a call to the special function mlfCreateColonIndex()
.
mlfCreateColonIndex()
index, which loosely interpreted means ``all,'' selects, for example, all the columns in a row or all the rows in a column.You can also use the mlfColon()
function, which is patterned after the MATLAB colon operator, to specify a vector subscript. For example, mlfColon(mlfSclar(1), mlfScalar(10), NULL)
specifies the vector[ 1 2 3 4 5 6 7 8 9 10 ]
.
Note You cannot index into an array with more dimensions than the array has, although you can use fewer dimensions. |
![]() | Terminology | Array Storage | ![]() |