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!