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");
eng.close();
}
}
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:
matlabroot/extern/engines/java/jar/engine.jar
But in my computer I just have a folder called phyton in this path
matlabroot/extern/engines
Where can I find the .jar file that I need ?
I am using Eclipse IDE by the way. thanks.

댓글 수: 3

Chibing Gng
Chibing Gng 2017년 2월 20일
could you find a solution? I have the same problem. By the way, it is 2016b
manan lalit
manan lalit 2017년 3월 2일
편집: manan lalit 2017년 3월 2일
I have the same issue. I used the code written by Manuel and ran it on Eclipse after adding the external Engine JAR file from MATLAB 2016b, and ran into the following error.
Exception in thread "main" java.lang.NoClassDefFoundError: com/mathworks/mvm/MvmTerminatedException
at application.Main.main(Main.java:7)
Caused by: java.lang.ClassNotFoundException: com.mathworks.mvm.MvmTerminatedException
Can anyone help or have suggestions about what else I could try?
I also have the same problem. Any one know the answer? :( please guys give some idea to sole the problem.

댓글을 달려면 로그인하십시오.

 채택된 답변

Guillaume
Guillaume 2017년 3월 2일

1 개 추천

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일

0 개 추천

With a simple test "example.java" 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);
eng.close();
}
}
Following commands work for me:
C:\JavaEngine\src>javac -classpath <matlabroot>\\extern\\engines\\java\\jar\\engine.jar
example.java
C:\JavaEngine\src>set PATH=<matlabroot>\\bin\\win64;%PATH%
C:\JavaEngine\src>java -classpath .;<matlabroot>\\extern\\engines\\java\\jar\\engine.jar
example

카테고리

도움말 센터File Exchange에서 Call MATLAB from Java에 대해 자세히 알아보기

질문:

2017년 2월 18일

답변:

2017년 3월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by