MATLAB Application Program Interface Reference | Help Desk |
mxCreateStructMatrix
Create an unpopulated 2-dimensional structuremxArray
#include "matrix.h" mxArray *mxCreateStructMatrix(int m, int n, int nfields, const char **field_names);m
The desired number of rows. This must be a positive integer.
nThe desired number of columns. This must be a positive integer.
nfieldsThe desired number of fields in each element.
field_namesThe desired list of field names.
A pointer to the created structuremxArray
, if successful; otherwise, returns NULL
. The most likely cause of failure is insufficient heap space to hold the returned mxArray
.
mxCreateStructMatrix
and mxCreateStructArray
are almost identical. The only difference is that mxCreateStructMatrix
can only create two-dimensional mxArrays
, while mxCreateStructArray
can create mxArrays
having two or more dimensions.
Create a two-dimensional structure mxArray
having the dimensions 5-by-7:
int rows=100, cols=1; int number_of_fields=4; const char *fieldnames[] = {"pressure", "wind speed", "wind direction", "dewpoint"}; mxArray *struct_array_ptr; /* Create a 100-by-1 structure mxArray. */ struct_array_ptr = mxCreateStructMatrix(rows, cols, number_of_fields, fieldnames); /* Populate the structure mxArray with data. */ ...The created structure
mxArray
is unpopulated. See the mxCreateStructArray
reference page for sample code demonstrating how to populate a structure mxArray
. For an additional example of mxCreateStructMatrix
, see mxCreateStructMatrix.c
in the mx
subdirectory of the examples
directory.
mxCreateStructArray