Tsung-Hsiang Wu
Tsung-Hsiang Wu

Reputation: 81

call MATLAB in Java via MatlabControl.java

Recently I am trying to write a java application that can execute matlab code but faced some problems.

First of all, I refer to the link: http://www.cs.virginia.edu/~whitehouse/matlab/JavaMatlab.html

It has some tips to execute matlab code under java application. I included the MatlabControl.java as well as jmi.jar, following the steps it gives.

but when I try to test just a piece of simple code as follows

package jmat;


public class MainProgram {

    public static void main(String[] args) {
        MatlabControl mc = new MatlabControl();
        mc.eval(new String("x=5;"));
    }

}

the console outputed the error as follows

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.mathworks.jmi.NativeMatlab.PostMatlabRunnable(JZ)V
    at com.mathworks.jmi.NativeMatlab.PostMatlabRunnable(Native Method)
    at com.mathworks.jmi.NativeMatlab.postMatlabRunnable(NativeMatlab.java:399)
    at com.mathworks.jmi.MatlabLooper.postMatlabRunnable(MatlabLooper.java:178)
    at com.mathworks.jmi.Matlab.whenMatlabReady(Matlab.java:1404)
    at jmat.MatlabControl.eval(MatlabControl.java:88)
    at jmat.MainProgram.main(MainProgram.java:8)

I have no idea why it failed in my program, does any one can help me?

Upvotes: 2

Views: 1365

Answers (1)

thatnerd2
thatnerd2

Reputation: 544

Actually, you will need more than just MatlabControl.java in order to use Matlabcontrol. I'm assuming you picked up the source file from Option #3 in the link; that's just how options #1 and #2 work inside.

Go to that link that you posted and look at Option #1. Go to the link posted there, http://matlabcontrol.googlecode.com and click on Downloads. The first jar, matlabcontrol-4.1.0.jar is the one you want.

Download that and include it in the build path of your project. Then follow the walkthrough guides that are posted online. Let me know if you have any additional questions.

Upvotes: 3

Related Questions