External Interfaces/API Reference | ![]() ![]() |
Set a field value of a structure array, given a field name and an index
C Syntax
#include "matrix.h" void mxSetField(mxArray *array_ptr, int index, const char *field_name, mxArray *value);
Arguments
array_ptr
Pointer to a structure mxArray
. Call mxIsStruct
to determine if array_ptr
points to a structure mxArray
.
index
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
. See mxCalcSingleSubscript
for details on calculating an index.
field_name
mxGetFieldNameByNumber
or mxGetFieldNumber
to determine existing field names.
value
mxArray
you are assigning.
Description
Use mxSetField
to assign a value
to the specified element of the specified field. In pseudo-C terminology, mxSetField
performs the assignment
array_ptr[index].field_name = value;
If there is already a value at the given position, the value
pointer you specified overwrites the old value pointer. However, mxSetField
does not free the dynamic memory that the old value pointer pointed to. Consequently, you should free this old mxArray
immediately before or after calling mxSetField
.
mxSetField(pa, index, "field_name", new_value_pa);
field_num = mxGetFieldNumber(pa, "field_name"); mxSetFieldByNumber(pa, index, field_num, new_value_pa);
Example
See mxcreatestructarray.c
in the mx
subdirectory of the examples
directory.
See Also
mxCreateStructArray
, mxCreateStructMatrix
, mxGetField
, mxGetFieldByNumber
, mxGetFieldNameByNumber
, mxGetFieldNumber
, mxGetNumberOfFields
, mxIsStruct
, mxSetFieldByNumber
![]() | mxSetDimensions | mxSetFieldByNumber | ![]() |