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.

Access Data

Read or write data to array

Use these functions to get information about a MATLAB® array, such as dimension and size, and to retrieve data elements based on type. Use these functions to write data to mxArray variables.

C Functions

expand all

mxGetNumberOfDimensionsNumber of dimensions in array
mxGetElementSizeNumber of bytes required to store each data element
mxGetDimensionsPointer to dimensions array
mxSetDimensionsModify number of dimensions and size of each dimension
mxGetNumberOfElementsNumber of elements in numeric array
mxCalcSingleSubscriptOffset from first element to desired element
mxGetMNumber of rows in array
mxSetMSet number of rows in array
mxGetNNumber of columns in array
mxSetNSet number of columns in array
mxGetScalarReal component of first data element in array
mxGetDoublesReal data elements in mxDOUBLE_CLASS array
mxSetDoublesSet real data elements in mxDOUBLE_CLASS array
mxGetSinglesReal data elements in mxSINGLE_CLASS array
mxSetSinglesSet real data elements in mxSINGLE_CLASS array
mxGetInt8sReal data elements in mxINT8_CLASS array
mxSetInt8sSet real data elements in mxINT8_CLASS array
mxGetUint8sReal data elements in mxUINT8_CLASS array
mxSetUint8sSet real data elements in mxUINT8_CLASS array
mxGetInt16sReal data elements in mxINT16_CLASS array
mxSetInt16sSet real data elements in mxINT16_CLASS array
mxGetUint16sReal data elements in mxUINT16_CLASS array
mxSetUint16sSet complex data elements in mxUINT16_CLASS array
mxGetInt32sReal data elements in mxINT32_CLASS array
mxSetInt32sSet real data elements in mxINT32_CLASS array
mxGetUint32sReal data elements in mxUINT32_CLASS array
mxSetUint32sSet complex data elements in mxUINT32_CLASS array
mxGetInt64sReal data elements in mxINT64_CLASS array
mxSetInt64sSet data elements in mxINT64_CLASS array
mxGetUint64sReal data elements in mxUINT64_CLASS array
mxSetUint64sSet complex data elements in mxUINT64_CLASS array
mxGetDataData elements in nonnumeric mxArray
mxSetDataSet pointer to data elements in nonnumeric mxArray
mxGetPr(Not recommended) Real data elements in mxDOUBLE_CLASS array
mxSetPr(Not recommended) Set real data elements in mxDOUBLE_CLASS array
mxGetComplexDoublesComplex data elements in mxDOUBLE_CLASS array
mxSetComplexDoublesSet complex data elements in mxDOUBLE_CLASS array
mxGetComplexSinglesComplex data elements in mxSINGLE_CLASS array
mxSetComplexSinglesSet complex data elements in mxSINGLE_CLASS array
mxGetComplexInt8sComplex data elements in mxINT8_CLASS array
mxSetComplexInt8sSet complex data elements in mxINT8_CLASS array
mxGetComplexUint8sComplex data elements in mxUINT8_CLASS array
mxSetComplexUint8sSet complex data elements in mxUINT8_CLASS array
mxGetComplexInt16sComplex data elements in mxINT16_CLASS array
mxSetComplexInt16sSet complex data elements in mxINT16_CLASS array
mxGetComplexUint16sComplex data elements in mxUINT16_CLASS array
mxSetComplexUint16sSet complex data elements in mxUINT16_CLASS array
mxGetComplexInt32sComplex data elements in mxINT32_CLASS array
mxSetComplexInt32sSet complex data elements in mxINT32_CLASS array
mxGetComplexUint32sComplex data elements in mxUINT32_CLASS array
mxSetComplexUint32sSet complex data elements in mxUINT32_CLASS array
mxGetComplexInt64sComplex data elements in mxINT64_CLASS array
mxSetComplexInt64sSet complex data elements in mxINT64_CLASS array
mxGetComplexUint64sComplex data elements in mxUINT64_CLASS array
mxSetComplexUint64sSet complex data elements in mxUINT64_CLASS array
mxGetImagDataImaginary data elements in numeric mxArray
mxSetImagDataSet imaginary data elements in numeric mxArray
mxGetPi(Not recommended) Imaginary data elements in mxDOUBLE_CLASS array
mxSetPi(Not recommended) Set imaginary data elements in mxDOUBLE_CLASS array
mxGetCharsPointer to character array data
mxGetLogicalsPointer to logical array data
mxGetClassIDClass of array
mxGetClassNameClass of array as string
mxSetClassNameStructure array to MATLAB object array
mxGetPropertyValue of public property of MATLAB object
mxSetPropertySet value of public property of MATLAB object
mxGetFieldPointer to field value from structure array, given index and field name
mxSetFieldSet field value in structure array, given index and field name
mxGetNumberOfFieldsNumber of fields in structure array
mxGetFieldNameByNumberPointer to field name from structure array, given field number
mxGetFieldNumberField number from structure array, given field name
mxGetFieldByNumberPointer to field value from structure array, given index and field number
mxSetFieldByNumberSet field value in structure array, given index and field number
mxAddFieldAdd field to structure array
mxRemoveFieldRemove field from structure array
mxGetCellPointer to element in cell array
mxSetCellSet contents of cell array
mxGetNzmaxNumber of elements in IR, PR, and PI arrays
mxSetNzmaxSet storage space for nonzero elements
mxGetIrSparse matrix IR array
mxSetIrIR array of sparse array
mxGetJcSparse matrix JC array
mxSetJcJC array of sparse array

Topics

Handle Sparse Arrays

This example shows how to populate a sparse matrix using the C Matrix API.

Handle 8-, 16-, 32-, and 64-Bit Data

This example shows how to use unsigned 16-bit integers in a MEX file using the C Matrix API.

Pass Structures and Cell Arrays in C MEX Files

This example shows how to pass structures and cell arrays to MEX files built with the C Matrix API.

Manipulate Multidimensional Numerical Arrays

You can manipulate multidimensional numerical arrays by using typed data access functions like mxGetDoubles and mxGetComplexDoubles.