主要内容

com.mathworks.engine.matlabengine

爪哇MATLAB作为计算引擎

描述

Thecom.mathworks.engine.matlabengine课程使用MATLAB®作为Java的计算引擎的过程®。该类提供Java语言和MATLAB之间的接口,使您能够评估Java的MATLAB功能和表达式。

创建

TheMatlabEngineclass provides static methods to start MATLAB and to connect to a shared MATLAB session synchronously or asynchronously. Only these static methods can instantiate this class:

不支金宝app持的启动选项

该引擎不支持这些MATLAB启动选项:金宝app

  • -H

  • -帮助

  • - ?

  • -n

  • -e

  • -softwareopengl

  • -logfile

有关MATLAB启动选项的信息,请参阅常用的启动选项

Method Summary

Static Methods

StartMatlab

同步启动MATLAB。

StartMatlabAsync

异步启动MATLAB。

Findmatlab

Find all available shared MATLAB sessions from a local machine synchronously.

FindmatlabAsync

从异步查找本地计算机的所有可用共享MATLAB会话。

ConnectMatlab

连接到本地计算机上的共享MATLAB会话。

ConnectMatlabasync

在异步上连接到本地计算机上的共享MATLAB会话。

getCurrentMatlab

Connect to the current MATLAB session when called from the MATLAB environment.

成员变量

null_writer

采用a writer that ignores the contents from the MATLAB command window.

Member Functions

Feval

使用参数同步评估MATLAB函数。

FevalAsync

通过异步评估MATLAB函数。

eval

Evaluate a MATLAB expression as a string synchronously.

estarync

将MATLAB表达式评估为异步。

可差异

同步从MATLAB基本工作区获取变量。

getVariableasync

Get a variable from the MATLAB base workspace asynchronously.

putVariable

Put a variable into the MATLAB base workspace synchronously.

putvariableasync

Put a variable into the MATLAB base workspace asynchronously.

断开

同步断开当前MATLAB会话的连接。

脱节

Disconnect from the current MATLAB session asynchronously.

辞职

Force the shutdown of the current MATLAB session synchronously.

辞职Async

Force the shutdown of the current MATLAB session asynchronously.

close

断开或终止当前MATLAB会话。

方法详细信息

StartMatlab

static MatlabEngine startMatlab(String[] options)

静态Matlabengine Startmatlab()

描述

同步启动MATLAB。

Parameters

字符串[]选项

启动选项用于启动MATLAB引擎。您可以指定多个启动选项。该引擎支持所有MATL金宝appAB启动选项,除了列出的选项不支金宝app持的启动选项。有关选项列表,请参见特定于平台的命令matlab (Windows),MATLAB(MACOS), 或者MATLAB(Linux)

返回

实例MatlabEngine

com.mathworks.engine.engineException

MATLABfails to start.

Example
字符串[]选项= {"-noFigureWindows", "-r", "cd H:"}; MatlabEngine eng = MatlabEngine.startMatlab(options);

StartMatlabAsync

静态未来 startmatlabasync(string []选项)

static Future startMatlabAsync()

描述

异步启动MATLAB。Once MATLAB has started, then cancel is a no-op.

Parameters

字符串[]选项

启动选项用于启动MATLAB引擎。您可以指定多个启动选项。该引擎支持所有MATL金宝appAB启动选项,除了列出的选项不支金宝app持的启动选项。有关选项列表,请参见特定于平台的命令matlab (Windows),MATLAB(MACOS), 或者MATLAB(Linux)

返回

实例Future

Example
未来 future = matlabengine.startmatlabasync();

Findmatlab

静态字符串[] findmatlab()

描述

同步在本地计算机上找到所有共享的MATLAB会话。

返回

An array of the names of all shared MATLAB sessions on the local machine, or an empty vector if there are no shared MATLAB sessions available on the local machine.

com.mathworks.engine.engineException

If there is a failure during the search for MATLAB sessions.

Example
String[] engines = MatlabEngine.findMatlab();

FindmatlabAsync

静态未来 findmatlabasync()

描述

异步在本地机器上找到所有共享的MATLAB会话。

返回

一个实例未来

Example
未来未来= matlabengine.findmatlabasync();

ConnectMatlab

静态Matlabengine ConnectMatlab(字符串名称)

静态Matlabengine ConnectMatlab()

描述

Connect to a shared session on local machine synchronously.

  • 如果指定共享MATLAB会话的名称,但是引擎找不到带有该名称的会话,则引擎会引发异常。

  • 如果您没有指定名称,并且没有共享MATLAB会话,则引擎启动了带有默认选项的新共享MATLAB会话。

  • 如果您不指定名称并且有共享的MATLAB会话可用,则引擎将连接到第一个可用的会话。

To connect to the current MATLAB session when called from the MATLAB environment, usegetCurrentMatlabinstead.

Parameters

String name

Name of the shared MATLAB session. UseFindmatlabto get the names of shared MATLAB sessions.

返回

一个实例MatlabEngine

com.mathworks.engine.engineException

MATLAB无法启动或连接。

Example
matlabengine Engine = matlabengine.connectMatlab();

ConnectMatlabasync

静态未来 connectmatlabasync(String name)

静态未来 connectmatlabasync

描述

异步连接到本地计算机上的共享MATLAB会话。行为与ConnectMatlab除了该机制是异步的。一旦与MATLAB建立了连接,则取消是一个无操作。

Parameters

String name

Name of the shared MATLAB session.

返回

一个实例Future

Example
Future future = MatlabEngine.connectMatlabAsync();

getCurrentMatlab

静态matlabengine getCurrentMatlab()

描述

Connect to the current MATLAB session when called from the MATLAB environment.

要连接到MATLAB会话时,请使用引擎应用程序ConnectMatlab

返回

一个实例MatlabEngine

com.mathworks.engine.engineException

来自用户线程的呼叫不支持。金宝app

Example
Matlabengine Engine = Matlabengine.getCurrentMatlab();

Feval

t feval(int nlhs,字符串func,Writer输出,作者错误,对象…args)

t feval(int nlhs,字符串func,object…args)

t feval(字符串弹性,作者输出,作者错误,对象…args)

T feval(String func, Object… args)

描述

使用输入参数同步评估MATLAB函数。

Parameters

String功能

MATLAB函数或脚本要评估的名称。

int nlhs

预期输出的数量。默认值为1。

IfNLHS大于1,返回的类型T一定是<对象[]>

IfNLHSis0,返回的类型T一定是或者

IfNLHSis1,返回的类型Tcan be the expected type or如果不知道该类型。

作者输出

流用于存储MATLAB函数的标准输出。如果未指定作者,则输出将写入命令窗口或终端。采用null_writer从MATLAB命令窗口中忽略输出。

作者错误

流用于存储MATLAB函数的标准误差。如果未指定作者,则输出将写入命令窗口或终端。采用null_writer从MATLAB命令窗口忽略错误消息。

Object... args

参数传递到MATLAB函数。

返回

Result of executing the MATLAB function

java.util.concurrent.CancellationException

MATLAB功能的评估被取消。

java.lang.interruptedException

MATLAB功能的评估中断。

java.lang.illegalstateException

MATLAB会话不可用。

com.mathworks.engine.MatlabExcecutionException

该功能中有MATLAB运行时错误。

com.mathworks.engine.UnsupportedTypeExeption

有一种不支持的数据类型。金宝app

com.mathworks.engine.matlabsyntaxexception

There is a syntax error in the MATLAB function.

Example
double结果= Engine.Feval(“ SQRT”,4);

FevalAsync

Future fevalAsync(int nlhs, String func, Writer output, Writer error, Object… args)

Future fevalAsync(int nlhs, String func, Object… args)

Future fevalAsync(String func, Writer output, Writer error, Object… args)

未来 fevalasync(字符串func,对象…args)

描述

Evaluate MATLAB functions with input arguments asynchronously.

Parameters

String功能

MATLAB函数或脚本要评估的名称。

int nlhs

预期输出的数量。默认为1

IfNLHS大于1,返回的类型T一定是<对象[]>

IfNLHSis0,返回的类型T一定是或者

IfNLHSis1,返回的类型Tcan be the expected type or如果不知道该类型。

作者输出

流用于存储MATLAB函数的标准输出。如果未指定作者,则输出将写入命令窗口或终端。采用null_writer从MATLAB命令窗口中忽略输出。

作者错误

流用于存储MATLAB函数的标准误差。如果未指定作者,则输出将写入命令窗口或终端。采用null_writer从MATLAB命令窗口忽略错误消息。

Object... args

参数传递到MATLAB函数。

返回

一个实例未来

java.lang.illegalstateException

MATLAB会话不可用。
Example
Future  future = Engine.fevalasync(“ SQRT”,4);

eval

void eval(String command, Writer output, Writer error)

void eval(String command)

描述

将MATLAB语句同步评估。

Parameters

String命令

MATLAB语句评估。

作者输出

流用于存储MATLAB语句的标准输出。如果未指定作者,则输出将写入命令窗口或终端。采用null_writer从MATLAB命令窗口中忽略输出。

作者错误

Stream used to store the standard error from the MATLAB statement. If you do not specify a writer, the output is written to the command window or terminal. Usenull_writer从MATLAB命令窗口忽略错误消息。

java.util.concurrent.CancellationException

MATLAB功能的评估被取消。

java.lang.interruptedException

MATLAB功能的评估中断。

java.lang.illegalstateException

MATLAB会话不可用。

com.mathworks.engine.MatlabExcecutionException

There is an error in the MATLAB statement during runtime.

com.mathworks.engine.matlabsyntaxexception

MATLAB语句中存在语法错误。

Example
Engine.eval(“结果= SQRT(4)”);

estarync

Future estarync(字符串命令,作者输出,作者错误)

Future estarync(字符串命令)

描述

Evaluate a MATLAB statement as a string asynchronously.

Parameters

String命令

MATLAB语句评估。

作者输出

流用于存储MATLAB语句的标准输出。如果未指定作者,则输出将写入命令窗口或终端。采用null_writer从MATLAB命令窗口中忽略输出。

作者错误

Stream used to store the standard error from the MATLAB statement. If you do not specify a writer, the output is written to the command window or terminal. Usenull_writer从MATLAB命令窗口忽略错误消息。

返回

一个实例未来

java.lang.illegalstateException

MATLAB会话不可用。

Example
Future  future = Engine.evalasync(“ sqrt(4)”);

可差异

t getVariable(字符串varname)

描述

从MATLAB基本工作区获取变量。

Parameters

字符串varname

MATLAB基本工作区中变量的名称。

返回

Variable passed from the MATLAB base workspace

java.util.concurrent.CancellationException

该功能的评估被取消。

java.lang.interruptedException

Evaluation of this function is interrupted.

java.lang.illegalstateException

MATLAB会话不可用。

Example
double myvar = Engine.getVariable(“ myvar”);

getVariableasync

Future getVariableAsync(String varName)

描述

Get a variable from the MATLAB base workspace asynchronously.

Parameters

字符串varname

Name of a variable in MATLAB base workspace.

返回

一个实例未来

java.lang.illegalstateException

MATLAB会话不可用。

Example
Future future = engine.getVariableAsync("myVar");

putVariable

void putvariable(字符串varname,t vardata)

描述

将变量放入MATLAB基本工作区。

Parameters

字符串varname

在MATLAB基本工作区中创建的变量的名称。

t vardata

在MATLAB基本工作区中创建变量的值。

java.util.concurrent.CancellationException

该功能的评估被取消。

java.lang.interruptedException

Evaluation of this function is interrupted.

java.lang.illegalstateException

MATLAB会话不可用。

Example
Engine.putVariable(“ MyVar”,100);

putvariableasync

未来putvariableasync(String varName, T varData)

描述

Put a variable into the MATLAB base workspace asynchronously.

Parameters

字符串varname

在MATLAB基本工作区中创建的变量的名称。

t vardata

在MATLAB基本工作区中创建变量的值。

返回

一个实例未来

java.lang.illegalstateException

MATLAB会话不可用。

Example
Future  future = Engine.putvariableasync(“ myvar”,100);

断开

void disconnect()

描述

与当前的MATLAB会话断开连接。

com.mathworks.engine.engineException

当前的MATLAB会话无法断开连接。

Example
Engine.disconnect();

脱节

未来脱节()

描述

与当前的MATLAB会话断开连接。

Example
Future  future = Engine.disconnectasync();

辞职

void quit()

描述

Force the shutdown of the current MATLAB session.

com.mathworks.engine.engineException

The current MATLAB session cannot be shut down.

Example
egine.quit();

辞职Async

未来 quitasync()

描述

强制当前MATLAB会话的关闭,而无需等待终止。

返回

一个实例未来

Example
Future  future = Engine.quitasync();

close

void Close()

描述

MatlabEngine提供关闭()method to implement thejava.lang.autoclosable接口MatlabEngineobjects. This关闭()method enables you to use a尝试- 借助Resources语句自动断开或终止语句末尾的MATLAB会话。

TheMatlabEngine关闭()方法根据上下文断开或终止当前MATLAB会话。

  • 如果Java进程以默认的非共享会话开始MATLAB会话,则关闭()terminates MATLAB.

  • If the MATLAB session is a shared session,关闭()断开MATLAB与此Java过程的连接。MATLAB在没有其他连接时终止。

要强制关闭或断开当前MATLAB会话的连接,请明确致电matlabengine.quit(),matlabengine.disconnect(),或他们的异步对应物。

Example
engine.close();
Introduced in R2016b