Using the C++ Math Library | ![]() ![]() |
Deleting Elements from a Cell Array
Cell arrays follow the same rules as numeric arrays and structure arrays for element deletion. You can delete a single element from a cell array, or an entire dimension element, for example, a row or column of a two-dimensional cell array or a row, column, or page of a three-dimensional cell array. In MATLAB, you delete elements by assigning []
to them. In the MATLAB C++ Math Library, you assign the null array.
Deleting a Single Element
In order to delete a single element from an array of any type, you must use one-dimensional indexing. Deleting a single element from a two-dimensional cell array collapses it into a vector cell array. For example, using one-dimensional indexing, N(2)
refers to element (2,1)
of N
. Deleting the (2,1)
element of N
(the complex number 2-4i
) produces a three-element cell array. In MATLAB you write N(2) = []
. See the graphical representation of N
on page 4-31.
You remove element (2,1)
from N
like this:
N(2) = empty();
Deleting an Entire Dimension
You can delete an entire dimension by using vector subscripting to delete a row or column of cells. Use parentheses within the indexing string to indicate that you are deleting the cells themselves.
N(2,colon()) = empty()
;
N(2,:) = []
performs the same operation in MATLAB.
![]() | Assigning Values to a Cell Array | Indexing into MATLAB Structure Arrays | ![]() |