Can I make a call to a third party Matlab function while using the Matlab Engine API along with Java?
조회 수: 3 (최근 30일)
이전 댓글 표시
I wish to use the MATLAB Engine API for running calculations along side a graphical user interface developed in Java on Eclipse IDE. Was wondering if it may be possible to make a call to third party functions written in MATLAB? Is there a way to zip a non-standard function along with the engine.jar found at the location: C:\Program Files\MATLAB\R2016b\extern\engines\java\jar ?
As a simple example, I would like to be able to run the function called 'apowb.m' which accepts two variables x1 and x2 and computes y=x1^x2.
function [ y ] = apowb( x1, x2 )
% This function evaluates y = x1 ^ x2
y=x1^(x2);
end
I make a reference to this function in my controller method in Java. Some snippets from that method are displayed below:
import com.mathworks.engine.MatlabEngine;
...
public class PersonOverviewController {
private static Future<MatlabEngine> engFuture;
private static MatlabEngine eng;
...
@FXML
private void calculate() throws Exception{
engFuture = MatlabEngine.startMatlabAsync();
eng = engFuture.get();
double input1=5;
double input2=6;
Future<Double> future = eng.fevalAsync("apowb", input1, input2);
System.out.println(future.get());
}
}
This throws a `null pointer exception' probably because the function "apowb" is not traced by the Java Compiler?
Caused by: java.lang.NullPointerException
at manan.gui.view.PersonOverviewController.calculate(PersonOverviewController.java:117)
댓글 수: 0
답변 (1개)
Bo Li
2017년 3월 15일
Did you add "apowb" to the MATLAB path? You can do that using addpath either in MATLAB or through feval in Java. The M file needs to be searchable in order to be found by Java Engine.
참고 항목
카테고리
Help Center 및 File Exchange에서 Java Package Integration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!