Question on MatlabEngine and Sharing Instances in Java
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
halcyon
am 4 Sep. 2024
String[] matinsts = MatlabEngine.findMatlab('a'); just find the engine which you have shared
0 Kommentare
Siehe auch
Kategorien
Mehr zu Call MATLAB from Java finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!