主要内容

从 C 调用 MATLAB

使用 mxArray 从 C 程序中运行 MATLAB® 代码

引擎应用程序是程序,它们允许您从自己的 C/C++ 程序调用 MATLAB,从而将 MATLAB 用作计算引擎。要编译 C 引擎应用程序,请调用 mex 函数。

注意

推荐使用 MATLAB Engine API for C++ 而不是 Engine API for C。MATLAB Engine API for C++ 包含用于编写引擎应用程序的现代 C++ 功能。有关详细信息,请参阅从 C++ 调用 MATLAB。目前没有删除 Engine API for C 的计划。

引擎应用程序需要已安装版本的 MATLAB;您无法在只有 MATLAB Runtime 的机器上运行 MATLAB Engine。

要编译 C Engine 应用程序,您需要:

  • 编写 C 源代码的经验。您可以使用 Engine API for C 和 C Matrix API 函数创建 C 源代码文件。

  • MATLAB 支持的编译器。有关支持的编译器的最新列表,请参阅支持和兼容的编译器

  • 使用具有 -client engine 选项的 mex 编译脚本。

Engine API for C

EngineMATLAB 引擎的类型
engOpenStart MATLAB engine session
engOpenSingleUseStart MATLAB engine session for single, nonshared use
engCloseQuit MATLAB engine session
engEvalStringEvaluate expression in string
engGetVariableCopy variable from MATLAB engine workspace
engPutVariablePut variable into MATLAB engine workspace
engGetVisibleDetermine visibility of MATLAB engine session
engSetVisibleShow or hide MATLAB engine session
engOutputBufferSpecify buffer for MATLAB output

主题

要求

编写引擎应用程序

编译和运行引擎应用程序

疑难解答

无法启动 MATLAB 引擎

当 MATLAB 引擎无法运行时该怎么办。

Debug MATLAB Function Called by C Engine

How to verify MATLAB functions used in engine applications.

User Input Not Supported

Some MATLAB functions that interact with the user are not supported in engine applications.

Multithreaded Applications

MATLAB libraries are not thread-safe.