Documentation

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

Arguments

pm

Pointer to an mxArray

Returns

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

Description

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
       mxCopyPtrToReal8(mxGetData(pm),data,
     +                  mxGetNumberOfElements(pm))

Examples

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?