[英]How can my Java program use MATLAB continuously without having to establish a connection everytime?
I have a MATLAB script running on a Java Eclipse project via the matlabcontrol.jar package. 我有一个通过matlabcontrol.jar包在Java Eclipse项目上运行的MATLAB脚本。
I have the following set-up 我有以下设置
MatlabProxyFactoryOptions options = new MatlabProxyFactoryOptions.Builder()
.setUsePreviouslyControlledSession(true)
.setHidden(true)
.setMatlabLocation(null).build();
MatlabProxyFactory factory = new MatlabProxyFactory(options);
MatlabProxy proxy = factory.getProxy();
//some code invoking the proxy.eval() method
The problem is that I have the MATLAB script running several times over the course of the runtime of the simulation. 问题是我在仿真的运行过程中使MATLAB脚本多次运行。 How can I make it so that Java doesn't have to reconnect with MATLAB every single time I want to use the MATLAB function? 如何使Java不必每次都想使用MATLAB函数重新与MATLAB连接?
Any help would be appreciated. 任何帮助,将不胜感激。
Thanks! 谢谢!
I'm not expert on JAVA, so I will give my solution in simple words that you can translate to JAVA world. 我不是JAVA的专家,所以我将用简单的词来介绍我的解决方案,您可以将其翻译为JAVA world。 :) :)
Eg: 例如:
public class MATLABConnector
{
private MATLABConnector con=new MATLABConnector();
MatlabProxyFactoryOptions options = new MatlabProxyFactoryOptions.Builder()
.setUsePreviouslyControlledSession(true)
.setHidden(true)
.setMatlabLocation(null).build();
MatlabProxyFactory factory = new MatlabProxyFactory(options);
private MATLABConnector()
{
// Do basic initializations.
}
private boolean checkConnecionStatus();
private boolean establishConnection();
public static MATLABProxy getProxy()
{
if(!con.checkConnectionStatus())
con.establishConnection();
return con.factory.getProxy();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.