Fill mxArray in C MEX File
Options
You can move data from a C MEX file into an mxArray using the C
Matrix API. The functions you use depend on the type of data in your application.
Use the mxSetDoubles and mxGetDoubles
functions for data of type double. For numeric data other than
double, use the one of the typed data access functions. For
nonnumeric data, see the examples for the mxCreateString function.
The following examples use a variable data to represent data
from a computational routine. Each example creates an mxArray
using the mxCreateNumericMatrix function, fills it with
data, and returns it as the output argument
plhs[0].
If you have complex data or the type is not double, then use
the Typed Data Access in C MEX Files
functions. The typed data access functions are part of the interleaved complex C
Matrix API; use the mex
-R2018a option to build the MEX functions.
Copying Data Directly into an mxArray
The arrayFillGetPr.c example uses the
mxGetDoubles function to copy the values from
data to plhs[0].
Pointing to Data
The arrayFillSetPr.c example uses the
mxSetDoubles function to point plhs[0]
to data. The arrayFillSetComplexPr.c example uses the
mxSetComplexDoubles function to point to complex
data.
The example arrayFillSetData.c shows how to fill an
mxArray for numeric types other than
double.
See Also
mxGetDoubles | mxSetDoubles | mxCreateString | mxSetComplexDoubles