MATLAB Application Program Interface Reference | Help Desk |
mxGetFieldNumber
Get a field number, given a field name in a structure array
#include "matrix.h" int mxGetFieldNumber(const mxArray *array_ptr, const char *field_name);array_ptr
Pointer to a structure mxArray
.
The name of a field in the structure mxArray
.
field_name,
on success. The first field has a field number of 0, the second field has a field number of 1, and so on. Returns -1
on failure. Common causes of failure include:
array_ptr
that does not point to a structure mxArray
. Call mxIsStruct
to determine if array_ptr
points to a structure mxArray
.
field_name
of a nonexistent field.
mxGetFieldNumber
. Conversely, if you know the field number but do not know its field name, call mxGetFieldNameByNumber
.
For example, consider a MATLAB structure initialized to
>> patient.name = 'John Doe'; >> patient.billing = 127.00; >> patient.test = [79 75 73; 180 178 177.5; 220 210 205];The
field_name
"name"
has a field number of 0; the field_name
"billing
" has a field_number
of 1; and the field_name
"test"
has a field number of 2. If you call mxGetFieldNumber
and specify a field_name
of anything other than "name
", "billing"
, or "test"
, then mxGetFieldNumber
returns -1
.
See mxGetFieldNumber.c
in the mx
subdirectory of the examples
directory.
mxGetField
, mxGetFieldByNumber
, mxGetFieldNameByNumber
, mxGetNumberOfFields
, mxSetField
, mxSetFieldByNumber