Main Content

mxSetPr (C)

(Not recommended) Set real data elements in mxDOUBLE_CLASS array

mxSetPr is not available in the interleaved complex API. Use mxSetDoubles or mxSetComplexDoubles instead. For more information, see Compatibility Considerations.

C Syntax

#include "matrix.h"
void mxSetPr(mxArray *pm, double *pr);


The mxSetPr function sets the real data of a real mxDOUBLE_CLASS array pm. If you build with the interleaved complex API (mex -R2018a option) and pm is complex, then the function terminates the MEX file and returns control to the MATLAB® prompt. In a non-MEX file application, the function returns NULL.

Call mxIsDouble to validate the mxArray type. Call mxIsComplex to determine whether the data is real.

All mxCreate* functions allocate heap space to hold data. Therefore, you do not ordinarily use this function to initialize the real elements of an array. Instead, call this function to replace the existing values with new values.

The mxSetPr function does not free memory allocated for existing data. To free existing memory, call mxFree on the pointer returned by mxGetPr.

Input Arguments

expand all

Pointer to a MATLAB array of type mxDOUBLE_CLASS, specified as mxArray *.

Pointer to the first mxDouble element of the real part of the data array within an mxArray, specified as double *. Each element in the array contains the real component of a value.

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. If pr points to static memory, then memory leaks and other memory errors can result.

Compatibility Considerations

expand all

Not recommended starting in R2018a

Errors starting in R2018a

Introduced before R2006a