Problems with MATLAB Engine API for Java

11 ビュー (過去 30 日間)
Manuel Rios
Manuel Rios 2017 年 2 月 18 日
回答済み: Bo Li 2017 年 3 月 15 日
I am trying to compile this piece of code:
import com.mathworks.engine.*;
public class javaEvalFunc {
public static void main(String[] args) throws Exception {
MatlabEngine eng = MatlabEngine.startMatlab();
eng.evalAsync("[X, Y] = meshgrid(-2:0.2:2);");
eng.evalAsync("Z = X .* exp(-X.^2 - Y.^2);");
Object[] Z = eng.getVariable("Z");
I found it on this web page: Java Engine
As you can see I need a reference to com.mathworks.engine.*;
This Page Info says that the .jar file that I need to Add is in this Path:
But in my computer I just have a folder called phyton in this path
Where can I find the .jar file that I need ?
I am using Eclipse IDE by the way. thanks.
  3 件のコメント
Anushan Vasantharajah
Anushan Vasantharajah 2017 年 3 月 2 日
I also have the same problem. Any one know the answer? :( please guys give some idea to sole the problem.



Guillaume 2017 年 3 月 2 日
It would help if you used the documentation that come with your version. In R2016a, you will find no mention of the java engine, and that's because it's been introduced in R2016 (See the release notes under advanced software development).
You will have to upgrade to R2016b.

その他の回答 (1 件)

Bo Li
Bo Li 2017 年 3 月 15 日
With a simple test "" like this:
import com.mathworks.engine.*;
public class CNN
public static void main(String[] args) throws Exception{
MatlabEngine eng = MatlabEngine.startMatlab();
double[] a = {2.0 ,4.0, 6.0};
double[] roots = eng.feval("sqrt", a);
Following commands work for me:
C:\JavaEngine\src>javac -classpath <matlabroot>\\extern\\engines\\java\\jar\\engine.jar
C:\JavaEngine\src>set PATH=<matlabroot>\\bin\\win64;%PATH%
C:\JavaEngine\src>java -classpath .;<matlabroot>\\extern\\engines\\java\\jar\\engine.jar

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by