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

Get a field value, given a field name and an index in a structure array

C Syntax

Arguments

array_ptr
  Pointer to a structure mxArray.

index
  The desired element. 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 structure mxArray.

field_name
  The name of the field whose value you want to extract.

Returns

A pointer to the mxArray 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

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

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.

When you finish using the returned mxArray, call mxDestroyArray to deallocate it. Note: Changing data contained within the field may cause unpredictable results.

Examples

Consider a MEX-file named WhatBill that prints the value of the "Billing" field in each element of an input structure mxArray:

In MATLAB, create a structure named patient initialized to

Passing patient as the first argument to WhatBill yields

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

See Also

mxGetFieldByNumber, mxGetFieldNameByNumber, mxGetFieldNumber, mxGetNumberOfFields, mxIsStruct, mxSetField, mxSetFieldByNumber



[ Previous | Help Desk | Next ]