mxGetElementSize (C and Fortran) - Get number of bytes required to store each data element

C Syntax

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

Fortran Syntax

mwSize mxGetElementSize(pm)
mwPointer pm

Arguments

pm

Pointer to an mxArray

Returns

The 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).

Description

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 particularly 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.

C Examples

See doubleelement.c and phonebook.c in the refbook subdirectory of the examples directory.

See Also

mxGetM, mxGetN

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS