| MATLAB Application Program Interface | Search  Help Desk |
| mxGetNumberOfFields | Examples See Also |
Get the number of fields in a structure mxArray
#include "matrix.h" int mxGetNumberOfFields(const mxArray *array_ptr);array_ptr
mxArray.
The number of fields, on success. Returns 0 on failure. The most common cause of failure is that array_ptr is not a structure mxArray. Call mxIsStruct to determine if array_ptr is a structure.
Call mxGetNumberOfFields to determine how many fields are in the specified structure mxArray.
Once you know the number of fields in a structure, it is easy to loop through every field in order to set or to get field values.
See the example in the mxGetFieldNameByNumber reference page, or mxgetnumberoffields.c in the mx subdirectory of the examples directory.
mxGetField, mxIsStruct, mxSetField