Java中的Matlabcontrol

时间:2015-09-15 14:02:14

标签: java matlab

我正在从https://code.google.com/p/matlabcontrol/wiki/Walkthrough开始研究以下程序。我希望使用Matlab控件在Java中调用Matlab函数。我在程序中导入了matlabcontrol。 前两个示例程序对我来说很好。

public static void main(String[] args) throws MatlabConnectionException, MatlabInvocationException
{
    //Create a proxy, which we will use to control MATLAB
    MatlabProxyFactory factory = new MatlabProxyFactory();
    MatlabProxy proxy = factory.getProxy();

    //Create a 4x3x2 array filled with random values
    proxy.eval("array = randn(4,3,2)");

    //Print a value of the array into the MATLAB Command Window
    proxy.eval("disp(['entry: ' num2str(array(3, 2, 1))])");

    //Get the array from MATLAB
    MatlabTypeConverter processor = new MatlabTypeConverter(proxy);
    MatlabNumericArray array = processor.getNumericArray("array");

    //Print out the same entry, using Java's 0-based indexing
    System.out.println("entry: " + array.getRealValue(2, 1, 0));

    //Convert to a Java array and print the same value again    
    double[][][] javaArray = array.getRealArray3D();
    System.out.println("entry: " + javaArray[2][1][0]);

    //Disconnect the proxy from MATLAB
    proxy.disconnect();
}

当我在Windows上运行此程序时,Java会给我以下错误:

C:\Program Files\Java\jdk1.6.0_45\bin>javac Helloworld3.java
Helloworld3.java:61: cannot find symbol
symbol  : class MatlabTypeConverter
location: class Helloworld3
    MatlabTypeConverter processor = new MatlabTypeConverter(proxy);
    ^
Helloworld3.java:61: cannot find symbol
symbol  : class MatlabTypeConverter
location: class Helloworld3
    MatlabTypeConverter processor = new MatlabTypeConverter(proxy);
                                        ^
Helloworld3.java:62: cannot find symbol
symbol  : class MatlabNumericArray
location: class Helloworld3
    MatlabNumericArray array = processor.getNumericArray("array");
    ^
3 errors

任何帮助将不胜感激! 感谢。

1 个答案:

答案 0 :(得分:1)

顺便说一句,我得到了答案。我们需要将文件导入为:

import matlabcontrol.extensions.MatlabTypeConverter;

现在,工作正常!