Fill mxArray

Options

You can move data from a C/C++ program into an mxArray using the Matrix Library. The functions you use depend on the type of data in your application. Use the mxSetPr and mxGetPr functions for data of type double. For numeric data other than double, use the mxSetData function. 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].

These examples use real data only. If you have complex data, use the mxGetPi and mxSetPi functions as needed.

Copying Data Directly into an mxArray

The arrayFillGetPr.c example uses the mxGetPr function to copy the values from data to plhs[0]. To see the example, open the fileopen the file in MATLAB® Editor.

Pointing to Data

The arrayFillSetPr.c example uses the mxSetPr function to point plhs[0] to data. To see the example, open the fileopen the file in MATLAB Editor.

The example arrayFillSetData.c illustrates how to fill an mxArray for numeric types other than double. To see the example, open the fileopen the file in MATLAB Editor.

Was this topic helpful?