我正在使用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


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

最佳答案

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

import matlabcontrol.extensions.MatlabTypeConverter;


现在,它工作正常!

07-27 23:22