目录
C MEX 文件应用程序
使用 mxArray,编写可用于 MATLAB® R2017b 或更早版本的 C 程序
可以像调用内置函数一样,从 MATLAB 命令行调用自己的 C 或 C++ 程序。这些程序称为 MEX 函数,并且函数名称为 MEX 文件名。MEX 函数并不适用于所有应用程序。MATLAB 是一种高生产率环境,尤其适用于消除编译语言中需要花费大量时间的低级编程。一般情况下,请在 MATLAB 中进行编程。除非您的应用程序需要,否则请不要使用 MEX 函数。
要创建 MEX 函数,请使用 MATLAB API 编写程序。这些库中的函数有助于在 MEX 函数和工作区之间传输数据。要选择 MATLAB API,请考虑以下几点。
-   
 MathWorks 建议使用现代 C++ 功能创建 MEX 函数,如 MATLAB 数据 API 中定义。可以参考C++ MEX 应用程序。
-  如果您的 MEX 函数必须在 MATLAB R2017b 或更早版本中运行,或如果更喜欢使用 C 语言,应使用 C 矩阵 API 和 C MEX API 中的函数。这些 API 使用 MATLAB mxArray 数据结构。此页上列出的函数和主题基于 mxArray。 
选择来自 C 矩阵 API 或 MATLAB Data API 的函数;不能混合使用来自这些 API 的函数。
使用mex函数将您的源文件编译到可执行程序中。也可以与其他 MATLAB 用户共享 MEX 文件。有关编写 S-Function 的信息,请参阅您的 Simulink® 文档。要调用其他人创建的 MEX 函数,可以参考MEX文件函数。
如果有 C/C++ 程序并且要从该程序中调用 MATLAB 函数,请使用其中一个引擎 API。
如果要在 C/C++ 程序中读取和写入 MATLAB 数据,可以使用用于读取MAT文件数据的MATLAB C API。
函数
| mex | 编译 MEX 函数或引擎应用程序 | 
| dbmex | 在 UNIX 平台上启用 MEX 文件调试 | 
C MEX API
| mexFunction | Entry point to C/C++ MEX function built with C Matrix API | 
| mexFunctionName | Name of current MEX function | 
| mexAtExit | Register function to call when MEX function clears or MATLAB terminates | 
| mexCallMATLAB | Call MATLAB function, user-defined function, or MEX function | 
| mexCallMATLABWithTrap | Call MATLAB function, user-defined function, or MEX file and capture error information | 
| mexEvalString | Execute MATLAB command in caller workspace | 
| mexEvalStringWithTrap | Execute MATLAB command in caller workspace and capture error information | 
| mexGetVariable | Copy of variable from specified workspace | 
| mexGetVariablePtr | Read-only pointer to variable from another workspace | 
| mexPutVariable | Array from MEX function into specified workspace | 
| mexGet | Value of specified graphics property | 
| mexSet | Set value of specified graphics property | 
| mexPrintf | ANSI C PRINTF-style output routine | 
| mexErrMsgIdAndTxt | Display error message with identifier and return to MATLAB prompt | 
| mexWarnMsgIdAndTxt | Warning message with identifier | 
| mexIsLocked | Determine if MEX file is locked | 
| mexLock | Prevent clearing MEX file from memory | 
| mexUnlock | Allow clearing MEX file from memory | 
| mexMakeArrayPersistent | Make array persist after MEX file completes | 
| mexMakeMemoryPersistent | Make memory allocated by MATLAB persist after MEX function completes | 










