Question on MatlabEngine and Sharing Instances in Java

2 ビュー (過去 30 日間)
Shiloh Greer
Shiloh Greer 2019 年 7 月 10 日
I am working in Java and trying to execute some MATLAB code. So far this has involved using the MatlabEngine class and using functions like eval(), which has worked great. However, I want other Java classes to have the ability to access any MATLAB variables created by the first class. I'm getting errors, however, and would appreciate any advice.
Here's the code that runs for the first class:
String[] matlines = {"cd '...'",
"sim(\"modelName\");",
"set_param('modelName','StartTime','0','StopTime','0');"};
MatlabEngine matinst = null;
matinst = MatlabEngine.startMatlab();
matinst.engine.shareEngine('a');
for (int i = 0; i < matlines.length; i++)
{
matinst.eval(matlines[i],null,null);
System.out.println( "Executed code from line " + i + " from matlabLineArr." );
}
Here's what I'm trying to run from an external class that operates after the above code has run:
String[] matinsts = MatlabEngine.findMatlab();
MatlabEngine matinst = MatlabEngine.connectMatlab(matinsts[0]);
double[] javaArr = matinst.getVariable("MatVect");
I have a sneaking suspsion that I'm trying to do two contradictory things, somehow, but I don't know what the issue is. Again, any advice would be appreciated.

回答 (0 件)

カテゴリ

Help Center および File ExchangeCall MATLAB from Java についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by