Fill mxArray in C MEX File - MATLAB & Simulink (original) (raw)

Main Content

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 thandouble, 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 withdata, and returns it as the output argumentplhs[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 themxGetDoubles function to copy the values fromdata to plhs[0].

Pointing to Data

The arrayFillSetPr.c example uses themxSetDoubles function to point plhs[0] to data. The arrayFillSetComplexPr.c example uses themxSetComplexDoubles function to point to complexdata.

The example arrayFillSetData.c shows how to fill anmxArray for numeric types other thandouble.

See Also

mxGetDoubles | mxSetDoubles | mxCreateString | mxSetComplexDoubles

Topics