TheodoraXasa
TheodoraXasa

Reputation: 31

call matlab's functions from java

I want to call eig() from my java file and i want that result to be returned in my file but i can't find any example. I found an example in that link :

http://www.devsrealm.com/java/calling-matlab-from-java/#comment-335

but the example with sqrt shows that error in matlab :

Error using sqrt Too many output arguments.

How i can call eig() from java and take bag V, D matrix? Any Help it would be very useful. thanks

Upvotes: 1

Views: 1381

Answers (3)

Joshua Kaplan
Joshua Kaplan

Reputation: 883

matlabcontrol is a Java API which will allow you to call MATLAB from Java. You can either call MATLAB from within MATLAB or from outside MATLAB in which case an instance of MATLAB is launched and connected to. It allows for invoking eval and feval in MATLAB and returning the results to MATLAB. The walkthrough explains with examples how to do this. The walkthrough details how you specify the correct number of return arguments for you to get the behavior you desire.

Upvotes: 2

CBass
CBass

Reputation: 993

If you read the comments section in the link you pasted, you will see that there is an error in the code example. The number of output arguments is set to 5 rather than 1. MATLAB is complaining because the MATLAB sqrt function returns 1 argument (hence the too many output arguments error).

Because MATLAB functions can return multiple arguments, the calling convention requires that you specify the number being returned to the calling code, and do so correctly.

Upvotes: 0

slayton
slayton

Reputation: 20319

Check out the Java Builder, it allows you to create Java classes from matlab code.

Upvotes: 0

Related Questions