This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

mxGetElementSize (C and Fortran)

Number of bytes required to store each data element

C Syntax

#include "matrix.h"
size_t mxGetElementSize(const mxArray *pm);

Fortran Syntax

#include "fintrf.h"
mwPointer mxGetElementSize(pm)
mwPointer pm



Pointer to an mxArray


Number of bytes required to store one element of the specified mxArray, if successful. Returns 0 on failure. The primary reason for failure is that pm points to an mxArray having an unrecognized class. If pm points to a cell mxArray or a structure mxArray, mxGetElementSize returns the size of a pointer (not the size of all the elements in each cell or structure field).


Call mxGetElementSize to determine the number of bytes in each data element of the mxArray. For example, if the MATLAB® class of an mxArray is int16, the mxArray stores each data element as a 16-bit (2-byte) signed integer. Thus, mxGetElementSize returns 2.

mxGetElementSize is helpful when using a non-MATLAB routine to manipulate data elements. For example, the C function memcpy requires (for its third argument) the size of the elements you intend to copy.


Fortran does not have an equivalent of size_t. mwPointer is a preprocessor macro that provides the appropriate Fortran type. The value returned by this function, however, is not a pointer.


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

See Also

mxGetM, mxGetN

Introduced before R2006a

Was this topic helpful?