Using the C++ Math Library | ![]() ![]() |
Dimensions and Subscripts in the MATLAB C++ Math Library
The MATLAB C++ Math Library supports N-dimensional standard, cell array, and structure indexing. You use:
()
for standard indexingmwArray::cell()
for cell array indexingmwArray::field()
for structure indexingThe indexing operator ()
and mwArray::cell()
take numeric arguments, one index for each dimension of the array being indexed. mwArray::field()
takes the name of the structure field as an argument.
Note You cannot index into an array with more dimensions than the array has, although you can use fewer dimensions. |
Applying a subscript to an array allows you to:
elements of an array. For example, the two-dimensional indexing expression
A(3,1)
applies the subscript (3,1)
to A
and returns the element at row 3, column 1. A(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. |
An index can be a scalar, a vector, a matrix, or a call to the special function colon()
.
colon()
index, which loosely interpreted means ``all,'' selects, for example, all the columns in a row or all the rows in a column.If you provide arguments to colon(),
the subscript specifies a vector. For example, colon(1,10)
specifies the vector [ 1 2 3 4 5 6 7 8 9 10 ]
.
The MATLAB C++ Math Library implements indexing via the interaction of three classes: mwArray
, mwIndex
, and mwSubArray
. mwArray
represents the array itself. mwIndex
represents an index. mwSubArray
represents the result of an index operation. The indexing routines themselves create mwSubArray
objects when an indexing expression appears as the target of an assignment operation (on the left-hand side of an assignment operator). The library handles mwSubArray
objects for you; you do not need to create them.
![]() | Dimensions and Subscripts in MATLAB | Array Storage | ![]() |