从 Java 中调用 MATLAB
编写可用于 MATLAB® 的 Java® 程序
以同步或异步方式从 Java 程序调用 MATLAB 函数和执行 MATLAB 语句。Java 程序可以将数据传递到 MATLAB 工作区,也可以从该工作区获取数据。该引擎支持用 JDK™ 编译的 Java 应用程序。有关版本信息,请参阅其他语言的 MATLAB 接口。
要从 MATLAB 调用 Java 函数,请参阅从 MATLAB 中调用 Java。
函数
类
主题
快速入门
- MATLAB Engine API for Java
该 API 使 Java 程序能够将 MATLAB 用作计算引擎。 - 编译 Java 引擎程序
设置环境变量、Java 类路径,编译并运行您的 Java 代码。 - Java Example Source Code
These examples show how to use the MATLAB Engine API for Java.
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
- Start and Close MATLAB Session from Java
Start the Java engine session synchronously or asynchronously and you can pass startup options to MATLAB. - Connect Java to Running MATLAB Session
Connect the Java engine to a running MATLAB session that has been started as or converted to a shared session. - 从 Java 执行 MATLAB 函数
将 Java 变量传递给 MATLAB 函数调用,并将值返回给 Java。 - Evaluate MATLAB Statements from Java
Evaluate MATLAB expressions from Java and write variables into the MATLAB base workspace. - Pass Variables from Java to MATLAB
Pass variables from Java to MATLAB as function arguments or by placing those variables in the MATLAB base workspace. - Pass Variables from MATLAB to Java
Get variables from the MATLAB workspace and map them to the appropriate Java type. - Redirect MATLAB Command Window Output to Java
Redirect standard output from the MATLAB command window to Java.
针对 Java 的专用 MATLAB 类型
- Using Complex Variables in Java
Define complex numbers in Java using theComplex
class. - Using MATLAB Structures in Java
Define MATLAB structure data types in Java using theStruct
class. - Pass Java CellStr to MATLAB
Define a MATLAB cell array of character vectors using the JavaCellStr
class. - Using MATLAB Handle Objects in Java
Return MATLAB handle objects to Java using the JavaHandleObject
class.
疑难解答
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
方法的调用中提供参量数目。
In certain cases, you must convert to specific MATLAB types to support the requirements of the MATLAB function you are calling.