This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

mxSetData (C)

Set pointer to data elements in nonnumeric mxArray

Use mxSetData for nonnumeric arrays only. mxSetData is not recommended for numeric arrays in C applications. Use typed data access functions instead. For more information, see Typed Data Access.

C Syntax

#include "matrix.h"
void mxSetData(mxArray *pm, void *pa);


Use mxSetData to set data elements for nonnumeric arrays only.

This function does not free memory allocated for existing data. To free existing memory, call mxFree on the pointer returned by mxGetData.

Input Arguments

expand all

Pointer to a nonnumeric mxArray.

Void pointer to an array of data.

The array must be in dynamic memory; call mxCalloc to allocate this memory. Do not use the ANSI® C calloc function, which can cause memory alignment issues leading to program termination.

API Version

Use this function for nonnumeric input arguments only. Otherwise, MathWorks recommends that you upgrade your MEX file to use the Typed Data Access functions instead.

This function is in the separate complex API. To build myMexFile.c using this function, type:

mex -R2017b myMexFile.c

This function is also in the interleaved complex API. However, the results are different for complex input argument pm.

  • If pm is a real array, then pa becomes the real component of pm.

  • If pm is complex array, then pa must also be complex. Otherwise, the elements of pa become interleaved real and imaginary values, not real-only values.

To build myMexFile.c using the interleaved complex API, type:

mex -R2018a myMexFile.c

See Also

Introduced before R2006a