【问题标题】:Exception in MatlabControl when running MATLAB function outside MATLAB在 MATLAB 之外运行 MATLAB 函数时,MatlabControl 中出现异常
【发布时间】:2012-06-29 10:24:57
【问题描述】:

我需要帮助才能通过 MatlabControl 在 Java 和 MATLAB 之间建立连接。

首先我想在演练中测试代码,但每次我都遇到相同的异常:

myfunc.m:

function myfunc()
    disp('hello from MYFUNC')
end

Java:

class ShowImage {

 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('E:\\vm')");
        proxy.feval("myfunc");
        proxy.eval("rmpath('E:\\vm)");

        // close connection
        proxy.disconnect();

}}

这里有例外:

Exception in thread "main" matlabcontrol.MatlabConnectionException: Could not launch MATLAB. Command: [matlab, -r, javaaddpath 'C:\Users\walaa\Desktop\matlabcontrol-4.0.0.jar'; matlabcontrol.MatlabClassLoaderHelper.configureClassLoading(); javarmpath 'C:\Users\walaa\Desktop\matlabcontrol-4.0.0.jar'; matlabcontrol.MatlabConnector.connectFromMatlab('PROXY_RECEIVER_42dd44d9-815e-41ad-bec9-e469718b5710', 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 ShowImage.main(ShowImage.java:19)
Caused by: java.io.IOException: Cannot run program "matlab": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(Unknown Source)
    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>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    ... 6 more

我不知道是什么问题,任何帮助将不胜感激!

【问题讨论】:

    标签: java matlab matlab-deployment


    【解决方案1】:

    我假设您使用的是来自here 的示例。显然它已经过测试并且可以工作,只要确保 MATLAB 在 Windows 路径上(错误消息表明它找不到程序“matlab.exe”)

    【讨论】:

    • 非常感谢 :) 现在它正在从 java 打开 matlab,但是你知道我是否可以通过 MatlabControl 将图像路径从 java 传递给 matlab,反之亦然?因为我正在使 java GUI 匹配两个数字,一个是我在 java GUI 上打开,另一个是 matlb 匹配函数的输出,如果你能在 MatlabControl 函数中指导我一点,因为我是新手, ,再次感谢。
    • @user1318251:尝试在以下行中调用 MATLAB 函数时传递图像名称:proxy.eval("myMatlabFunction('/path/to/image.png')");
    • 我按照你说的做了,但我得到了这个错误“错误使用 eval Undefined function 'hgr' for input arguments of 'char'”,而我的 matlab 函数是
    • 你能帮我吗?我问了一个新问题stackoverflow.com/questions/11279998/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多