mxGetData (C and Fortran)

Pointer to real numeric data elements in array

C Syntax

#include "matrix.h"
void *mxGetData(const mxArray *pm);

Fortran Syntax

mwPointer mxGetData(pm)
mwPointer pm



Pointer to an mxArray


Pointer to the first element of the real data. Returns NULL in C (0 in Fortran) if there is no real data.


In C, mxGetData returns a void pointer (void *). Since void pointers point to a value that has no type, you must cast the return value to the pointer type that matches the type specified by pm. To see how MATLAB® types map to their equivalent C types, see the table on the mxClassID reference page.

In Fortran, to copy values from the returned pointer, use one of the mxCopyPtrTo* functions in the following manner:

C      Get the data in mxArray, pm
     +                  mxGetNumberOfElements(pm))


See the following examples in matlabroot/extern/examples/mex.

See the following examples in matlabroot/extern/examples/refbook.

See the following examples in matlabroot/extern/examples/mx.

Was this topic helpful?