Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

C Matrix API

使用 C Matrix API 创建使用 mxArray 类型表示 MATLAB 数据的 C 程序

要编写可用于 MATLAB® R2017b 或更早版本的 C 程序,请使用 C Matrix API 中的函数。这些函数支持 mxArray 数据结构,用于编译 C MEX 函数或 C Engine 应用程序。

注意

尽可能选择 C++ 而不是 C 应用程序。

有两个版本的 C Matrix API。

有关使用这些库函数的示例,请参阅:

小心

C Matrix API 与支持现代 C++ 功能的 MATLAB Data API for C++ 不兼容。您不能将 C Matrix API 函数与编写可从 MATLAB(MEX 文件)调用的 C++ 函数从 C++ 调用 MATLAB 中所述的 MATLAB API 中的函数一起使用。

C 数据类型

mxArrayMATLAB 数组的 C 类型
mwSizeC 类型的 mxArray 大小值
mwIndexC type for mxArray index values
mwSignedIndexSigned integer C type for mxArray size values
mxCharType for string array
mxLogicalType for logical array
mxComplexity指定数组是否有虚部的标志

mxArray 属性

mxIsNumericDetermine whether mxArray is numeric
mxIsComplexDetermine whether data is complex
mxGetNumberOfDimensionsmxArray 中的维数
mxGetElementSizeNumber of bytes required to store each data element
mxGetDimensions指向维度数组的指针
mxSetDimensionsModify number of dimensions and size of each dimension
mxGetNumberOfElements数值 mxArray 中的元素数
mxCalcSingleSubscriptOffset from first element to desired element
mxGetMmxArray 中的行数
mxSetMSet number of rows in mxArray
mxGetNmxArray 中的列数
mxSetNSet number of columns in mxArray
mxIsEmptyDetermine whether mxArray is empty
mxIsFromGlobalWSDetermine whether mxArray was copied from MATLAB global workspace

创建、查询和访问数据类型

全部展开

mxCreateDoubleMatrix二维双精度浮点数组
mxCreateDoubleScalar将标量双精度数组初始化为指定值
mxCreateNumericMatrix二维数值矩阵
mxCreateNumericArrayN-D numeric array
mxCreateUninitNumericMatrixUninitialized 2-D numeric matrix
mxCreateUninitNumericArrayUninitialized N-D numeric array
mxIsScalarDetermine whether array is scalar array
mxGetScalarReal component of first data element in array
mxIsDoubleDetermine whether mxArray represents data as double-precision, floating-point numbers
mxGetDoublesmxDOUBLE_CLASS 数组中的实数数据元素
mxSetDoublesmxDOUBLE_CLASS 数组中的设置实数数据元素
mxIsSingleDetermine whether mxArray represents data as single-precision, floating-point numbers
mxGetSinglesmxSINGLE_CLASS 数组中的实数数据元素
mxSetSinglesSet real data elements in mxSINGLE_CLASS array
mxGetPr(Not recommended) Real data elements in mxDOUBLE_CLASS array
mxSetPr(Not recommended) Set real data elements in mxDOUBLE_CLASS array
mxIsInt8Determine whether mxArray represents data as signed 8-bit integers
mxGetInt8sReal data elements in mxINT8_CLASS array
mxSetInt8sSet real data elements in mxINT8_CLASS array
mxIsUint8Determine whether mxArray represents data as unsigned 8-bit integers
mxGetUint8sReal data elements in mxUINT8_CLASS array
mxSetUint8sSet real data elements in mxUINT8_CLASS array
mxIsInt16Determine whether mxArray represents data as signed 16-bit integers
mxGetInt16sReal data elements in mxINT16_CLASS array
mxSetInt16sSet real data elements in mxINT16_CLASS array
mxIsUint16Determine whether mxArray represents data as unsigned 16-bit integers
mxGetUint16sReal data elements in mxUINT16_CLASS array
mxSetUint16sSet real data elements in mxUINT16_CLASS array
mxIsInt32Determine whether mxArray represents data as signed 32-bit integers
mxGetInt32sReal data elements in mxINT32_CLASS array
mxSetInt32sSet real data elements in mxINT32_CLASS array
mxIsUint32Determine whether mxArray represents data as unsigned 32-bit integers
mxGetUint32sReal data elements in mxUINT32_CLASS array
mxSetUint32sSet real data elements in mxUINT32_CLASS array
mxIsInt64Determine whether mxArray represents data as signed 64-bit integers
mxGetInt64sReal data elements in mxINT64_CLASS array
mxSetInt64sSet data elements in mxINT64_CLASS array
mxIsUint64Determine whether mxArray represents data as unsigned 64-bit integers
mxGetUint64sReal data elements in mxUINT64_CLASS array
mxSetUint64sSet real data elements in mxUINT64_CLASS array
mxGetComplexDoublesmxDOUBLE_CLASS 数组中的复数数据元素
mxSetComplexDoublesSet complex data elements in mxDOUBLE_CLASS array
mxGetComplexSinglesmxSINGLE_CLASS 数组中的复数数据元素
mxSetComplexSinglesSet complex data elements in mxSINGLE_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
mxGetComplexInt8smxINT8_CLASS 数组中的复数数据元素
mxSetComplexInt8sSet complex data elements in mxINT8_CLASS array
mxGetComplexUint8smxUINT8_CLASS 数组中的复数数据元素
mxSetComplexUint8sSet complex data elements in mxUINT8_CLASS array
mxGetComplexInt16smxINT16_CLASS 数组中的复数数据元素
mxSetComplexInt16sSet complex data elements in mxINT16_CLASS array
mxGetComplexUint16smxUINT16_CLASS 数组中的复数数据元素
mxSetComplexUint16sSet complex data elements in mxUINT16_CLASS array
mxGetComplexInt32smxINT32_CLASS 数组中的复数数据元素
mxSetComplexInt32sSet complex data elements in mxINT32_CLASS array
mxGetComplexUint32smxUINT32_CLASS 数组中的复数数据元素
mxSetComplexUint32sSet complex data elements in mxUINT32_CLASS array
mxGetComplexInt64smxINT64_CLASS 数组中的复数数据元素
mxSetComplexInt64sSet complex data elements in mxINT64_CLASS array
mxGetComplexUint64smxUINT64_CLASS 数组中的复数数据元素
mxSetComplexUint64sSet complex data elements in mxUINT64_CLASS array
mxGetPi(Not recommended) Imaginary data elements in mxDOUBLE_CLASS array
mxSetPi(Not recommended) Set imaginary data elements in mxDOUBLE_CLASS array
mxCreateSparse2-D sparse array
mxCreateSparseLogicalMatrix2-D, sparse, logical array
mxIsSparseDetermine whether input is sparse mxArray
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
mxGetDataData elements in nonnumeric mxArray
mxSetDataSet pointer to data elements in nonnumeric mxArray
mxCreateString初始化为指定字符串的一维数组
mxCreateCharMatrixFromStrings2-D mxChar array initialized to specified value
mxCreateCharArrayN-D mxChar array
mxIsChar确定输入是否为 mxChar 数组
mxGetCharsPointer to character array data
mxIsLogicalDetermine whether mxArray is of type mxLogical
mxIsLogicalScalarDetermine whether scalar array is of type mxLogical
mxIsLogicalScalarTrueDetermine whether scalar array of type mxLogical is true
mxClassIDEnumerated value identifying class of array
mxCreateLogicalArrayN-D logical array
mxCreateLogicalMatrix2-D logical array
mxCreateLogicalScalarScalar, logical array
mxGetLogicalsPointer to logical array data
mxIsClassDetermine whether mxArray is object of specified class
mxGetClassIDClass of mxArray
mxGetClassNameClass of mxArray as string
mxSetClassNameStructure array to MATLAB object array
mxGetPropertyValue of public property of MATLAB object
mxSetPropertySet value of public property of MATLAB object
mxCreateStructMatrix二维结构体数组
mxCreateStructArrayN-D structure array
mxIsStructDetermine whether mxArray is structure
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
mxCreateCellMatrix2-D cell array
mxCreateCellArrayN-D cell array
mxIsCellDetermine whether mxArray is cell array
mxGetCellPointer to element in cell array
mxSetCellSet contents of cell array

删除并复制 mxArray

mxDestroyArrayFree dynamic memory allocated by MXCREATE* functions
mxDuplicateArrayMake deep copy of array

转换 mxArray

全部展开

mxMakeArrayComplexConvert real mxArray to complex, preserving real data
mxMakeArrayRealConvert complex mxArray to real, preserving real data
mxArrayToStringArray to string
mxArrayToUTF8StringArray to string in UTF-8 encoding
mxGetStringmxChar array to C-style string or Fortran character array
mxSetClassNameStructure array to MATLAB object array

数据内存管理

mxCallocAllocate dynamic memory for array, initialized to 0, using MATLAB memory manager
mxMallocAllocate uninitialized dynamic memory using MATLAB memory manager
mxReallocReallocate dynamic memory using MATLAB memory manager
mxFreeFree dynamic memory allocated by mxCalloc, mxMalloc, mxRealloc, mxArrayToString, or mxArrayToUTF8String functions

断言

mxAssertCheck assertion value for debugging purposes
mxAssertSCheck assertion value without printing assertion text

常量

mxIsInfDetermine whether input is infinite
mxIsFiniteDetermine whether input is finite
mxIsNaNDetermine whether input is NaN (Not-a-Number)

主题