Using the C++ Math Library | ![]() ![]() |
Assigning Values to a Cell Array
You put a value into a cell array in much the same way that you read a value out of a cell array. In MATLAB, the only difference between the two operations is the position of the cell array relative to the assignment operator: left of the equal sign (=
) means assignment, right of the operator means reference. No matter if you're reading or writing values, the indexing operations you use to specify which values to access remain the same. This is true in the MATLAB C++ Math Library as well.
mwArray::cell()
in indexing expressions for cell array assignments.For example, to assign a vector [1 2 5 7 11]
to the contents of the cell (1,2)
of N
, you write N{1,2} = [1 2 5 7 11]
in MATLAB and
N.cell(1,2) = horzcat(1, 2, 5, 7, 11);
in C++ with the MATLAB C++ Math Library.
You could have written the previous assignment in MATLAB asN(1,2) = { [1 2 5 7 11] }
. The corresponding MATLAB C++ Math Library code is:
N(1,2) = cellhcat(horzcat(1, 2, 5, 7, 11));
Because this assignment uses parentheses instead of braces, it is an assignment between cells, which means the source array (on the right-hand side of the assignment operator) must be a cell array as well.
![]() | Indexing Nested Cell Arrays | Deleting Elements from a Cell Array | ![]() |