MATLAB Application Program Interface Reference | Help Desk |
mxSetCell
Set the value of one cell
#include "matrix.h" void mxSetCell(mxArray *array_ptr, int index, mxArray *value);array_ptr index
Index from the beginning of the mxArray
. Specify the number of elements between the first cell of the mxArray
and the cell you wish to set. The easiest way to calculate index
is to call mxCalcSingleSubscript
.
The new value of the cell. You can put any kind of mxArray
into a cell. In fact, you can even put another cell mxArray
into a cell.
mxSetCell
to put the designated value
into a particular cell of a cell mxArray
. Use mxSetCell
to assign new values to unpopulated cells or to overwrite the value of an existing cell.
If the specified cell is already occupied, then mxSetCell
assigns the new value
. However, the old cell value remains in memory until you call mxDestroyArray
.
For an example of using mxSetCell
to populate cells in a freshly created cell mxArray
, see mxCreateCellArray
.
Consider a function that calls mxSetCell
to change the value already held in the first cell element.
void modify_first_cell(mxArray *cell_array_ptr, mxArray *new_value) { int index_of_first_cell=0; mxArray *old_value; /* Get pointer to old cell. */ old_value = mxGetCell(cell_array_ptr, index_of_first_cell); /* Free the memory that the old_value was using. */ mxDestroyArray(old_value); /* Assign the new value to the first cell. */ mxSetCell(cell_array_ptr, index_of_first_cell, new_value); }For an additional example, see
mxSetCell.c
in the mx
subdirectory of the examples
directory.
mxCreateCellArray
, mxCreateCellMatrix
, mxGetCell
, mxIsCell