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

Java 调用 MATLAB

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

以同步或异步方式从 Java 程序调用 MATLAB 函数和计算 MATLAB 语句。Java 程序可以将数据传递到 MATLAB 基础工作区,也可以从工作区获取数据。该引擎支持使用 JDK™ 7 或更高版本编译的 Java 应用程序。

要从 MATLAB 调用 Java 函数,请参阅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.HandleObjectJava class to represent MATLAB handle objects

主题

快速入门

用于 Java 的 MATLAB 引擎 API

该 API 使 Java 程序能够将 MATLAB 用作计算引擎。

编译 Java 引擎程序

设置环境变量、Java 类路径,编译并运行您的 Java 代码。

Java Example Source Code

These examples show how to use the MATLAB Engine API for Java.

Java 引擎 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.

使用针对 MATLABJava 引擎 API

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 the Complex class.

Using MATLAB Structures in Java

Define MATLAB structure data types in Java using the Struct class.

Pass Java CellStr to MATLAB

Define a MATLAB cell array of character vectors using the Java CellStr class.

Using MATLAB Handle Objects in Java

Return MATLAB handle objects to Java using the Java HandleObject class.

Java 使用 MATLAB 功能

Run Simulink Simulation from Java

You can run Simulink® simulations and return results to Java.

疑难解答

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.

Incorrect Number of Output Arguments

If you are calling a MATLAB function with no or more than one output argument, you must provide that number in calls to the engine feval method.

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.

相关信息