你可以启动一个MATLAB®会话从您的Java®同步或异步编程。使用这些MatlabEngine
静态
启动MATLAB的方法:
matlabengine.startmatlab.
- 同步启动MATLAB会话。
MatlabEngine.startMatlabAsync
异步启动MATLAB会话。
您应该始终使用中的方法之一来终止MATLAB会话关闭MATLAB引擎会话.
从Java同步启动MATLAB。
进口com.mathworks.engine。*;public class StartMatlab {public static void main(String[] args) throws Exception {MatlabEngine eng = MatlabEngine. StartMatlab ();...eng.close ();} }
从Java异步启动MATLAB。使用得到
返回的方法未来
对象来等待MatlabEngine
对象。
进口com.mathworks.engine。*;进口java.util.concurrent.Future;public class StartMatlab {public static void main(String[] args) throws Exception {FutureengFuture = MatlabEngine. startmatlabasync ();//在MATLAB引擎启动时工作…MatlabEngine eng = engFuture.get();...eng.close ();} }
您可以在启动MATLAB会话时指定MATLAB启动选项。有关MATLAB启动选项的信息,请参见常用启动选项.
的matlabengine.startmatlab.
和MatlabEngine.startMatlabAsync
方法接受字符串数组作为输入。
用MATLAB启动选项同步启动引擎。
进口com.mathworks.engine。*;public class StartMatlab {String[] options = {"-noFigureWindows", "-r", "cd H:"};public static void main(String[] args) throws Exception {MatlabEngine eng = MatlabEngine. startmatlab (options);...eng.close ();} }
用MATLAB启动选项异步启动引擎。
进口com.mathworks.engine。*;进口java.util.concurrent.Future;public class StartMatlab {public static void main(String[] args) throws Exception {String[] options = {"-noFigureWindows", "-r", "cd H:"};FutureengFuture = MatlabEngine. startmatlabasync (options);...MatlabEngine eng = engFuture.get();...eng.close ();} }
要结束MATLAB引擎会话,使用其中一个MatlabEngine
方法:
方法 | 目的 |
---|---|
如果Java进程将MATLAB会话作为默认的非共享会话启动, 如果MATLAB会话是共享会话, |
|
同步或异步断开当前MATLAB会话。 |
|
强制关闭当前MATLAB会话同步或异步。 |
com.mathworks.engine.MatlabEngine