本页对应的英文页面已更新,但尚未翻译。 若要查看最新内容,请点击此处访问英文页面。

用于 C 的 MATLAB 引擎 API

使用 mxArray 编写可用于 MATLAB® 的 C/C++ 程序

注意

用于 C 的引擎 API 中的函数支持 C 矩阵 API 中定义的 MATLAB mxArray 数据结构。要使用现代 C++ 功能编写应用程序,请参阅 用于 C++ 的 MATLAB 引擎 API

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

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

C 引擎 API 函数

EngineType for MATLAB engine
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

主题

编写引擎应用程序

Getting Started

What to do to start building C engine applications.

适用于 C 和 Fortran 的 MATLAB 引擎 API 简介

使用 MATLAB 作为计算引擎,从您自己的 C 和 Fortran 程序中调用 MATLAB。

从 C 应用程序中调用 MATLAB 函数

创建一个 C 引擎应用程序 engdemo.c

Attach to Existing MATLAB Sessions

This example shows how to attach an engine program to a MATLAB session that is already running.

Callbacks in Applications

Design user interface callbacks to be evaluated in the context of the base workspace.

编译和运行 Windows 应用程序

Set Run-Time Library Path on Windows Systems

At run time, tell the operating system where the API shared libraries are by setting the Path environment variable.

Build Windows Engine Application

This example shows how to verify the build process on Windows® platforms using the C example engwindemo.c.

Run Windows Engine Application

This example shows how to run the C example, engwindemo.c, from the Windows system prompt.

Register MATLAB as a COM Server

Register MATLAB for every session, to ensure that the current version of MATLAB is the registered version.

编译和运行 Mac 应用程序

Set Run-Time Library Path on macOS Systems

Tell the operating system where the API shared libraries are by setting the DYLD_LIBRARY_PATH environment variable.

Build Engine Application on macOS

This example shows how to verify the build process on a macOS platform.

Run Engine Application on macOS

This example shows how to run the C example engdemo.c from the macOS Terminal Window.

编译和运行 Linux 应用程序

在 Linux 系统上设置运行时库路径

通过设置 LD_LIBRARY_PATH 环境变量,告诉操作系统 API 共享库的位置。

Build Engine Application on Linux

This example shows how to verify the build process on a Linux® platform.

Run Engine Application on Linux

This example shows how to run the C example engdemo.c from the Linux system prompt.

在集成开发环境中编译

使用 IDE 编译引擎应用程序

关于配置您的集成开发环境来编译引擎应用程序的提示。

疑难解答

Can't Start MATLAB Engine

What to do when MATLAB engine does not run.

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.