How to run MATLAB code from Java?

天涯浪子 提交于 2019-12-18 06:39:33

问题


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


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


Here is a package that allows you to deploy MATLAB code as java classes.




回答5:


There are 2 ways for doing this :

  1. Use the Matlab Engine which has a C interface (see the link of the first answer for that). It is mandatory to have Matlab installed on all the machines on which you want to run this (see Matlab license for details)
  2. Use the Matlab Builder for Java which compiles the matlab code and produce a Java interface of your functions directly. With this solution, you need to by the Matlab compiler and the Matlab Builder for Java but you can then deploy your solution without paying anything more. Note that you must install the Matlab Compiler Runtime (MCR) on each machine but this is free.


来源:https://stackoverflow.com/questions/2130539/how-to-run-matlab-code-from-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!