Main Content

Java 中调用 MATLAB

编写可用于 MATLAB® 的 Java® 程序

以同步或异步方式从 Java 程序调用 MATLAB 函数和执行 MATLAB 语句。Java 程序可以将数据传递到 MATLAB 工作区,也可以从该工作区获取数据。该引擎支持用 JDK™ 编译的 Java 应用程序。有关版本信息,请参阅其他语言的 MATLAB 接口

要从 MATLAB 调用 Java 函数,请参阅从 MATLAB 中调用 Java

函数

全部展开

matlab.engine.shareEngine将正在运行的 MATLAB 会话转换为共享会话
matlab.engine.engineName返回共享 MATLAB 会话的名称
matlab.engine.isEngineShared确定 MATLAB 会话是否共享

全部展开

com.mathworks.engine.MatlabEngineJava class using MATLAB as a computational engine
com.mathworks.matlab.types.ComplexJava class to pass complex data to and from MATLAB
com.mathworks.matlab.types.StructJava class to pass MATLAB struct to and from MATLAB
com.mathworks.matlab.types.CellStrJava class to represent MATLAB cell array of char vectors
com.mathworks.matlab.types.HandleObjectAbstract Java class to represent MATLAB handle objects
com.mathworks.matlab.types.ValueObjectAbstract Java class to represent MATLAB value objects (自 R2021a 起)

主题

快速入门

Java Engine API 概述

  • Java Engine API Summary
    Here is a summary of the classes and methods available to use the MATLAB Engine API for Java.
  • Java Data Type Conversions
    The MATLAB engine API provides mappings to pass Java data types to MATLAB and pass MATLAB data types to Java, including Java classes to accommodate MATLAB handle objects, cellstrs, structures, and complex arrays.

使用 MATLAB Engine API for Java

针对 Java 的专用 MATLAB 类型

疑难解答

MATLAB Engine API Exceptions

The MATLAB Engine API for Java defines specific exception classes for MATLAB.

Pass Java Array Arguments to MATLAB

MATLAB and Java display multidimensional arrays differently, but indexed references to array elements produce the same results.

输出参数数目不正确

如果您要调用不带输出参数或带多个输出参数的 MATLAB 函数,则必须在对引擎 feval 方法的调用中提供参数数目。

Incorrect Java Data Types

In certain cases, you must convert to specific MATLAB types to support the requirements of the MATLAB function you are calling.