MATLAB Application Program Interface
  Go to function:
    Search    Help Desk 
mxGetFieldNameByNumber    Examples   See Also

Get a field name, given a field number in a structure array

C Syntax

Arguments

array_ptr
  Pointer to a structure mxArray.

field_number
  The position of the desired field. For instance, to get the name of the first field, set field_number to 0; to get the name of the second field, set field_number to 1; and so on.

Returns

A pointer to the nth field name, on success. Returns NULL on failure. Common causes of failure include:

You must allocate space to hold the returned field name. You should allocate enough memory to hold a string mxMAXNAM characters long.

Description

Call mxGetFieldNameByNumber to get the name of a field in the given structure mxArray. A typical use of mxGetFieldNameByNumber is to call it inside a loop in order to get the names of all the fields in a given mxArray.

Consider a MATLAB structure initialized to

The field_number 0 represents the field name "name"; field_number 1 represents field name "billing"; field_number 2 represents field name "test". A field_number other than 0, 1, or 2 causes mxGetFieldNameByNumber to return NULL.

Examples

Create a MEX-file named SeeStruc that tells you the names of each field in an input structure mxArray:

In MATLAB, create a structure named patient

Passing patient to SeeStruc yields

For an additional example, see mxgetfieldnamebynumber.c in the mx subdirectory of the examples directory.

See Also

mxGetField, mxIsStruct, mxSetField



[ Previous | Help Desk | Next ]