Main Content

Fill mxArray in C MEX File

Options

You can move data from a C MEX file into anmxArrayusing the C Matrix API. The functions you use depend on the type of data in your application. Use themxSetDoublesandmxGetDoublesfunctions for data of typedouble. For numeric data other thandouble, use the one of the typed data access functions. For nonnumeric data, see the examples for themxCreateStringfunction.

The following examples use a variabledatato represent data from a computational routine. Each example creates anmxArrayusing themxCreateNumericMatrixfunction, fills it withdata, and returns it as the output argumentplhs[0].

如果你有复杂的数据类型或不是double, then use theTyped Data Access in C MEX Filesfunctions. The typed data access functions are part of the interleaved complex C Matrix API; use themex-R2018aoption to build the MEX functions.

Copying Data Directly into an mxArray

ThearrayFillGetPr.cexample uses themxGetDoublesfunction to copy the values fromdatatoplhs[0].

Pointing to Data

ThearrayFillSetPr.cexample uses themxSetDoublesfunction to pointplhs[0]todata. ThearrayFillSetPrComplex.cexample uses themxSetComplexDoublesfunction to point to complexdata.

The examplearrayFillSetData.cshows how to fill anmxArrayfor numeric types other thandouble.

See Also

|||

Related Topics