user24094
user24094

Reputation: 294

Matlabcontrol in Java

I was working on the following program from https://code.google.com/p/matlabcontrol/wiki/Walkthrough. I wish to call Matlab function in Java using Matlab control. I imported matlabcontrol in the program. First 2 sample programs worked fine for me.


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();
}

When I run this program on Windows, Java gives me the following errors:

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

Any help would be appreciated! Thanks.

Upvotes: 1

Views: 1196

Answers (1)

user24094
user24094

Reputation: 294

BTW, I got the answer. We need to import a file as:

import matlabcontrol.extensions.MatlabTypeConverter;

Now, it is working fine!

Upvotes: 1

Related Questions