C Matrix API
mxArray
类型表示 MATLAB 数据的 C 程序要编写可用于 MATLAB® R2017b 或更早版本的 C 程序,请使用 C Matrix API 中的函数。这些函数支持 mxArray
数据结构,用于编译 C MEX 函数或 C Engine 应用程序。
注意
尽可能选择 C++ 而不是 C 应用程序。
有两个版本的 C Matrix API。
自 MATLAB R2018a 起,交错式复矩阵 API 包含 C 矩阵 API 功能。有关详细信息,请参阅MATLAB Support for Interleaved Complex API in MEX Functions。
自 MATLAB R2017b 起,分离式复矩阵 API 包含 C 矩阵 API 功能。
有关使用这些库函数的示例,请参阅:
请参阅各函数了解示例信息。例如,请参阅
mxIsChar
。
小心
C Matrix API 与支持现代 C++ 功能的 MATLAB Data API for C++ 不兼容。您不能将 C Matrix API 函数与编写可从 MATLAB(MEX 文件)调用的 C++ 函数 或 从 C++ 调用 MATLAB 中所述的 MATLAB API 中的函数一起使用。
C 数据类型
mxArray | MATLAB 数组的 C 类型 |
mwSize | C 类型的 mxArray 大小值 |
mwIndex | C type for mxArray index values |
mwSignedIndex | Signed integer C type for mxArray size values |
mxChar | Type for string array |
mxLogical | Type for logical array |
mxComplexity | 指定数组是否有虚部的标志 |
mxArray 属性
mxIsNumeric | Determine whether mxArray is numeric |
mxIsComplex | Determine whether data is complex |
mxGetNumberOfDimensions | mxArray 中的维数 |
mxGetElementSize | Number of bytes required to store each data element |
mxGetDimensions | Pointer to dimensions array |
mxSetDimensions | Modify number of dimensions and size of each dimension |
mxGetNumberOfElements | 数值 mxArray 中的元素数 |
mxCalcSingleSubscript | Offset from first element to desired element |
mxGetM | mxArray 中的行数 |
mxSetM | Set number of rows in mxArray |
mxGetN | Number of columns in mxArray |
mxSetN | Set number of columns in mxArray |
mxIsEmpty | Determine whether mxArray is empty |
mxIsFromGlobalWS | Determine whether mxArray was copied from MATLAB global workspace |
创建、查询和访问数据类型
删除并复制 mxArray
mxDestroyArray | Free dynamic memory allocated by MXCREATE* functions |
mxDuplicateArray | Make deep copy of array |
转换 mxArray
数据内存管理
mxCalloc | Allocate dynamic memory for array, initialized to 0, using MATLAB memory manager |
mxMalloc | Allocate uninitialized dynamic memory using MATLAB memory manager |
mxRealloc | Reallocate dynamic memory using MATLAB memory manager |
mxFree | Free dynamic memory allocated by mxCalloc, mxMalloc, mxRealloc, mxArrayToString, or mxArrayToUTF8String functions |
断言
常量
mxIsInf | Determine whether input is infinite |
mxIsFinite | Determine whether input is finite |
mxIsNaN | Determine whether input is NaN (Not-a-Number) |
主题
- Pass Strings in C MEX File
This example shows how to pass strings to a MEX function built with the C Matrix API.
- Pass Scalar Values in C MEX File
This example shows how to write a MEX file that passes scalar values.
- Handle Sparse Arrays in C MEX File
This example shows how to populate a sparse matrix using the C Matrix API.
- Handle 8-, 16-, 32-, and 64-Bit Data in C MEX File
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 File
This example shows how to pass structures and cell arrays to MEX files built with the C Matrix API.
- Manipulate Multidimensional Numerical Arrays in C MEX Files
You can manipulate multidimensional numerical arrays by using typed data access functions like
mxGetDoubles
andmxGetComplexDoubles
.