| MATLAB Application Program Interface | Search  Help Desk |
| mxGetField | See Also |
Get a field value, given a field name and an index in a structure array
C Syntax
#include "matrix.h" mxArray *mxGetField(const mxArray *array_ptr, int index, const char *field_name);
Arguments
array_ptrmxArray.
index
mxArray has an index of 0, the second element has an index of 1, and the last element has an index of N-1, where N is the total number of elements in the structure mxArray.
field_name
Returns
A pointer to themxArray in the specified field at the specified field_name, on success. Returns NULL otherwise. One possibility is that there is no value assigned to the specified field. Another possibility is that there is a value, but the call failed. Common causes of failure include:
array_ptr that does not point to a structure mxArray. To determine if array_ptr points to a structure mxArray, call mxIsStruct.
index to an element past the end of the mxArray. For example, given a structure mxArray that contains 10 elements, you cannot specify an index greater than 9.
field_name. Call mxGetFieldNameByNumber or mxGetFieldNumber to get existing field names.
mxArray.
Description
CallmxGetField to get the value held in the specified element of the specified field. In pseudo-C terminology, mxGetField returns the value at
array_ptr[index].field_name
mxGetFieldByIndex is similar to mxGetField. Both functions return the same value. The only difference is in the way you specify the field. mxGetFieldByIndex takes field_num as its third argument, and mxGetField takes field_name as its third argument.
Note: Changing data contained within the field may cause unpredictable results.
Calling
mxGetField(pa, index, "field_name");is equivalent to calling
field_num = mxGetFieldNumber(pa, "field_name"); mxGetFieldByNumber(pa, index, field_num);where
index is zero if you have a one-by-one structure.
See Also
mxGetFieldByNumber, mxGetFieldNameByNumber, mxGetFieldNumber, mxGetNumberOfFields, mxIsStruct, mxSetField, mxSetFieldByNumber