mxGetFieldByNumber (C and Fortran) - Get field value, given field number and index into structure array

C Syntax

#include "matrix.h"
mxArray *mxGetFieldByNumber(const mxArray *pm, mwIndex index, 
         int fieldnumber);

Fortran Syntax

mwPointer mxGetFieldByNumber(pm, index, fieldnumber)
mwPointer pm
mwIndex index
integer*4 fieldnumber

Arguments

pm

Pointer to a structure mxArray

index

Index of the desired element.

In C, the first element of an 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 mxArray.

In Fortran, the first element of an mxArray has an index of 1, the second element has an index of 2, and the last element has an index of N, where N is the total number of elements in the mxArray.

See mxCalcSingleSubscript for more details on calculating an index.

fieldnumber

The position of the field whose value you want to extract

In C, the first field within each element has a field number of 0, the second field has a field number of 1, and so on. The last field has a field number of N-1, where N is the number of fields.

In Fortran, the first field within each element has a field number of 1, the second field has a field number of 2, and so on. The last field has a field number of N, where N is the number of fields.

Returns

A pointer to the mxArray in the specified field for the desired element, 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:

Description

Call mxGetFieldByNumber to get the value held in the specified fieldnumber at the indexed element.

In C, calling:

mxGetField(pa, index, "field_name");

is equivalent to calling:

field_num = mxGetFieldNumber(pa, "field_name");
mxGetFieldByNumber(pa, index, field_num);

where index is 0 if you have a 1-by-1 structure.

In Fortran, calling:

mxGetField(pm, index, 'fieldname')

is equivalent to calling:

fieldnum = mxGetFieldNumber(pm, 'fieldname')
mxGetFieldByNumber(pm, index, fieldnum)

where index is 1 if you have a 1-by-1 structure.

C Examples

See phonebook.c in the refbook subdirectory of the examples directory.

Additional examples:

See Also

mxGetField, mxGetFieldNameByNumber, mxGetFieldNumber, mxGetNumberOfFields, mxIsStruct, mxSetField, mxSetFieldByNumber

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS