mxGetField (C and Fortran)
Pointer to field value from structure array, given index and field name
C Syntax
#include "matrix.h" mxArray *mxGetField(const mxArray *pm, mwIndex index, const char *fieldname);
Fortran Syntax
#include "fintrf.h" mwPointer mxGetField(pm, index, fieldname) mwPointer pm mwIndex index character*(*) fieldname
Arguments
pmPointer to a structure
mxArrayindexIndex of the desired element.
In C, the first element of an
mxArrayhas anindexof0. Theindexof the last element isN-1, whereNis the number of elements in the array. In Fortran, the first element of anmxArrayhas anindexof1. Theindexof the last element isN, whereNis the number of elements in the array.fieldnameName of the field whose value you want to extract.
Returns
Pointer to the mxArray in the specified field at the specified
fieldname, on success. Returns NULL in C
(0 in Fortran) if passed an invalid argument or if there is no
value assigned to the specified field. Common causes of failure include:
Specifying an array pointer
pmthat does not point to a structuremxArray. To determine whetherpmpoints to a structuremxArray, callmxIsStruct.Specifying an
indexto an element outside the bounds of themxArray. For example, given a structuremxArraythat contains 10 elements, you cannot specify anindexgreater than9in C (10in Fortran).Specifying a nonexistent
fieldname. CallmxGetFieldNameByNumberormxGetFieldNumberto get existing field names.Insufficient heap space.
Description
Call mxGetField to get the value held in the specified element of
the specified field. In pseudo-C terminology, mxGetField returns
the value at:
pm[index].fieldname
mxGetFieldByNumber is like mxGetField. Both
functions return the same value. The only difference is in the way you specify the
field. mxGetFieldByNumber takes a field number as its third
argument, and mxGetField takes a field name as its third
argument.
Do not call mxDestroyArray on an mxArray
returned by the mxGetField function.
Note
Inputs to a MEX file are constant read-only mxArrays. Do not modify the
inputs. Using mxSetCell* or
mxSetField* functions to modify the cells or
fields of a MATLAB® argument causes unpredictable results.
In C, calling:
mxGetField(pa, index, "field_name");
is equivalent to calling:
field_num = mxGetFieldNumber(pa, "field_name"); mxGetFieldByNumber(pa, index, field_num);
where, if you have a 1-by-1 structure,
index is 0.
In Fortran, calling:
mxGetField(pm, index, 'fieldname')
is equivalent to calling:
fieldnum = mxGetFieldNumber(pm, 'fieldname') mxGetFieldByNumber(pm, index, fieldnum)
where, if you have a 1-by-1 structure,
index is 1.
See Also
mxGetFieldByNumber, mxGetFieldNameByNumber, mxGetFieldNumber, mxGetNumberOfFields, mxIsStruct,
mxSetField,
mxSetFieldByNumber
Version History
Introduced before R2006a