Problems with using MATLAB Engine API for Java.
3 次查看(过去 30 天)
显示 更早的评论
Hello,
I wish to use the MATLAB Engine API in order to handle data and use MATLAB functions, in conjunction with a Java Front-End for the purpose of a graphical user interface.
To begin with, I tried playing with some sample code. As a first step, I added the external library (`Engine.jar') to my project in Eclipse:
Next, I wrote the following `test code' in order to check for effective compilation:
package application;
import com.mathworks.engine.*;
public class Main {
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();
}
}
Following is the hierarchy of files in my Java project:
This leads to the following error message:
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
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
Can anyone suggest what I need to do differently here? Thanks in advance.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call MATLAB from Java 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!