请帮帮我!当我尝试使用 java 中的 matlabcontrol 调用我的 matlab 函数时,它告诉我系统找不到指定的文件。
package matcontro;
import matlabcontrol.*;
public class HelloWorld
{
public static void main(String[] args) throws MatlabConnectionException, MatlabInvocationException
{
// create proxy
MatlabProxyFactoryOptions options = new MatlabProxyFactoryOptions.Builder()
.setUsePreviouslyControlledSession(true)
.build();
MatlabProxyFactory factory = new MatlabProxyFactory(options);
MatlabProxy proxy = factory.getProxy();
// call builtin function
proxy.eval("disp('hello world')");
// call user-defined function (must be on the path)
proxy.eval("addpath('C:\\ Users\\HASENDE\\My Documents\\MATLAB')");
proxy.feval("myfunc");
proxy.eval("rmpath('C:\\ Users\\HASENDE\\My Documents\\MATLAB')");
// close connection
proxy.disconnect();
}
}
我得到的错误如下;
跑:
Exception in thread "main" matlabcontrol.MatlabConnectionException: Could not launch MATLAB. Command: [matlab, -r, javaaddpath 'C:\Users\HASENDE\Documents\NetBeansProjects\Java Classpath Libraries\matlabcontrol-4.0.0.jar'; matlabcontrol.MatlabClassLoaderHelper.configureClassLoading(); javarmpath 'C:\Users\HASENDE\Documents\NetBeansProjects\Java Classpath Libraries\matlabcontrol-4.0.0.jar'; matlabcontrol.MatlabConnector.connectFromMatlab('PROXY_RECEIVER_01caa56d-9ed7-4e39-a45b-345051024d49', 2100);]
at matlabcontrol.RemoteMatlabProxyFactory.createProcess(RemoteMatlabProxyFactory.java:305) at matlabcontrol.RemoteMatlabProxyFactory.requestProxy(RemoteMatlabProxyFactory.java:116)
at matlabcontrol.RemoteMatlabProxyFactory.getProxy(RemoteMatlabProxyFactory.java:134)
at matlabcontrol.MatlabProxyFactory.getProxy(MatlabProxyFactory.java:81)
at matcontro.HelloWorld.main(HelloWorld.java:21)
Caused by: java.io.IOException: Cannot run program "matlab": CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) at matlabcontrol.RemoteMatlabProxyFactory.createProcess(RemoteMatlabProxyFactory.java:292) ... 4 more
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:188)
at java.lang.ProcessImpl.start(ProcessImpl.java:132)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1021) ... 5 more
Java Result: 1
构建成功(总时间:4 秒)