Using the C++ Math Library | ![]() ![]() |
Overview
A cell array is a regularly shaped N-dimensional array of cells. Each cell is capable of containing any type of MATLAB data, including another cell array. When using cell arrays, you must be careful to distinguish between the data values stored in the cells and the cells themselves, which are data values in their own right.
MATLAB supports two types of indexing on cell arrays. The first, standard indexing, uses parentheses ()
and allows you to manipulate the cells in a cell array. The second, cell array indexing, uses braces {}
to manipulate the data values stored in the cells.
The MATLAB C++ Math Library supports the same two types of indexing on cell arrays. Standard indexing uses parentheses ()
. Cell array indexing uses mwArray::cell()
to manipulate the data values stored in the cells. You pass index values to cell()
.
For example, given the cell array N
, above, N{2,2}
in MATLAB and N.cell(2,2)
in the MATLAB C++ Math Library is the scalar 7
, but N(2,2)
is a 1-by-1 cell array (a single cell) containing the scalar 7
.
Tips for Working with Cell Arrays
N(2,2)+1
, which attempts to add one to a cell. However, N.cell(2,2)+1
works perfectly well, because the cell array indexing returns the contents of cell (2,2)
rather than the cell itself.colon()
index to refer to multiple rows or columns; you can use vector and matrix indices to extract sub-cell arrays from a cell array.For simplicity, this section focuses on two-dimensional cell arrays. If N
were a cell array of higher dimension, the examples would still work on N
, if you added the appropriate number of dimensions to the indexing expressions.
![]() | Indexing into Cell Arrays | Referencing a Cell in a Cell Array | ![]() |