I am facing problem in running MATLAB code from Java. If you know something on this, could u please help me out?
Instead of using the undocumented JMI (Java MATLAB Interface) mentioned by Yair, you can use matlabcontrol which is a Java API that wraps around JMI which makes it much easier to use. It is well documented and has an introductory walkthrough. Unlike directly using JMI, it can also be used when running a Java program outside MATLAB.
If you don't want to buy MathWork's MATLAB Builder for Java Toolbox, you can use MATLAB's undocumented JMI (Java-MATLAB Interface). Search the CSSM newsgroup (or Google) for JMI, or JMatLink which is based on JMI. The MATLAB code itself is full of JMI usage examples - search "jmi" using the MATLAB Editor's search tool over the entire MATLAB installation.
Note that JMI is neither documented nor officially supported by MathWorks. Moreover, if improperly used it can hang or crash your application. But it's free, unlike the toolbox.
I have used Java Builder for running matlab scripts/functions in java application, and it seems to be very easy and helpful.
For this purpose, you need to have Java Builder JA toolbox to deploye matlab script/function as java class.
You then need to add the (converted) java class in to your java project library, and additionally the javabuilder jar file.
After doing the above steps you can easily run the matlab script (which is now a java class in the project library) just by calling the class name in the code. If the class is a matlab function, you can pass the paramenters and get the return values easily.
But offcourse, it is not the only method to do it. But this one seems easy to me comparatively.
I hope this answers to your question.
Here is a package that allows you to deploy MATLAB code as java classes.
There are 2 ways for doing this :