Using the C Math Library | ![]() ![]() |
Deleting Elements from a Structure Array
There are three kinds of deletion operations you can perform on a structure array.
Deleting a Structure from the Array
To delete an entire structure from a structure array, use mlfIndexDelete()
. For example, if you have a three-element array of image structures, you can delete the second image structure like this:
mlfIndexDelete(&images, "(?)", mlfScalar(2));
images(2) = []
performs the same operation in MATLAB. The result is a two-element array of image structures.
Deleting a Field from All the Structures in an Array
To delete a field from all the structures in the array, use mlfRmfield()
. For example, you can remove the description field from an array of image structures with this code:
mlfAssign(&images, mlfRmfield(images, mxCreateString("description")));
images = rmfield(images, 'description')
performs the same operation in MATLAB.
Note that rmfield()
does not allow you to remove a field of a nested structure from a structure array. For example, you cannot remove the day
field of the nested date
structure with this MATLAB code:
rmfield(images.date,'
day'
)
This is an error in MATLAB, and the corresponding call to mlfRmfield()
is an error in the MATLAB C Math Library.
Deleting an Element from an Array Contained by a Field
To delete an element from an array contained by a field, use mlfIndexDelete()
. For example, to remove the fifth column of the image in the third image structure, call mlfIndexDelete()
like this:
mlfIndexDelete(&images, "(?).image(?,?)", mlfScalar(3), mlfCreateColonIndex(), mlfScalar(5));
images(3).image(:,5) = []
performs the same operation in MATLAB.
![]() | Accessing the Contents of Structures Within Cells | Comparison of C and MATLAB Indexing Syntax | ![]() |