This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

mxGetElementSize (C)

Number of bytes required to store each data element

For a complex mxArray built with the interleaved complex API, mxGetElementSize returns twice the value that the function in the separate complex API returns.

C Syntax

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

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 helpful when using a non-MATLAB routine to manipulate data elements. For example, the C function memcpy requires the size of the elements you intend to copy.

Input Arguments

expand all

Pointer to an mxArray.

Output Arguments

expand all

Number of bytes required to store one element of the specified mxArray.

If pm is complex numeric, then the data in the output argument depends on which version of the C Matrix API you use.

  • If you build with the interleaved complex API (mex -R2018a option), then the return value is sizeof(std::complex<T>), where T is the data type of the array.

  • If you build with the separate complex API (mex -R2017b option), then the function returns the number of bytes for the data type of the array regardless whether the array is complex or real.

If pm points to a cell or structure, then mxGetElementSize returns the size of a pointer. The function does not return the size of all the elements in each cell or structure field.

Returns 0 on failure. The primary reason for failure is that pm points to an mxArray having an unrecognized class.

Examples

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

See Also

|

Introduced before R2006a