Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run MATLAB code from Java?

I am facing problem in running MATLAB code from Java. If you know something on this, could u please help me out?

like image 498
Deepak Avatar asked Jan 25 '10 06:01

Deepak


People also ask

Do I need Java to run MATLAB?

You must have MATLAB Compiler SDK installed. Your Java environment must be properly configured. For details, see Configure Your Environment for Generating Java Packages. Your end users must have MATLAB or MATLAB Runtime installed to run compiled MATLAB code.

How do you call a Java function in MATLAB?

In general, use MATLAB syntax to call methods on Java objects. Alternatively, use Java syntax. javaMethod( StaticMethodName , ClassName , x1,...,xN ) calls the static method in class ClassName . In general, use MATLAB syntax to call static methods on Java objects.

Has an API for Java and can be integrated with MATLAB?

The MATLAB® Engine API for Java® enables Java programs to interact with MATLAB synchronously or asynchronously, including: Start and terminate MATLAB. Connect to and disconnect from MATLAB sessions on the local machine.

Can I run MATLAB code in Python?

There are two approaches for calling MATLAB code from Python. The first is to use the MATLAB Engine API for Python, which requires a MATLAB install. The second is to use MATLAB Compiler SDK to compile a Python package that does not require users to have a MATLAB install.


2 Answers

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.

like image 116
Yair Altman Avatar answered Sep 28 '22 15:09

Yair Altman


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.

like image 22
Joshua Kaplan Avatar answered Sep 28 '22 15:09

Joshua Kaplan