JAVA can't analysis "simOut.get" method when getting Simulink output using engine API

3 ビュー (過去 30 日間)
YF Xie
YF Xie 2022 年 4 月 2 日
回答済み: Himanshu 2023 年 9 月 21 日
I've set my Simulink model output to workspace in a "simOut" object. And my JAVA code could running my Simulink model successfully. But, when I'm trying to get Simulink output from engine API using "eval" method, JAVA threw "MatlabExecutionException". My code basicly base on Matlab Help document "Run Simulink Simulation from Java":
Future<Void> fSim = eng.evalAsync(
"simOut = sim('xxx.slx','SaveOutput','on','OutputSaveName','yOut','SaveTime','on','TimeSaveName','tOut');");
while (!fSim.isDone()) {
System.out.println(
"Running xxx Simulation...");
Thread.sleep(10000);
}
// Get simulation data in matlab workspace
eng.eval("t = simOut.get('tOut');");
eng.eval("Xe = simOut.get('Xe');");
The error is:
com.mathworks.engine.MatlabExecutionException:
at com.mathworks.javaenginecore.JavaEngineFeval.nativefeval(Native Method)
at com.mathworks.javaenginecore.JavaEngineFeval.feval(JavaEngineFeval.java:38)
at com.mathworks.engine.MatlabEngine.feval(MatlabEngine.java:540)
at com.mathworks.engine.MatlabEngine.feval(MatlabEngine.java:505)
at com.mathworks.engine.MatlabEngine.eval(MatlabEngine.java:376)
at call_matlab.Main.xxx(Main.java:1984)
at call_matlab.Main.enterState(Main.java:1859)
at call_matlab.Main.executeActionOf(Main.java:1916)
at com.anylogic.engine.TransitionTimeout.execute(Unknown Source)
at com.anylogic.engine.Engine.a(Unknown Source)
at com.anylogic.engine.Engine.nm(Unknown Source)
at com.anylogic.engine.Engine.f(Unknown Source)
at com.anylogic.engine.Engine$i.run(Unknown Source)
Caused by: com.mathworks.engine.MatlabException: 无法解析名称 simOut.get。
... 13 more
com.mathworks.engine.MatlabException: 无法解析名称 simOut.get
Now I'm wodering if "simOut" object didn't created in the workspace, but using API to run Simulink from JAVA can't show workspace information in Matlab interface. Please give me some help, thanks!

回答 (1 件)

Himanshu
Himanshu 2023 年 9 月 21 日
Hi,
I understand that you are trying use the engine API’s eval function to access the output of your Simulink model from the MATLAB workspace. The error that is being encountered here translates to : Unable to resolve name simOut.get. This error is occurring because the properties of ‘simOut’ object are not accessed properly. The possible approaches to access the properties would be as follow:
eng.eval("t = simOut.tOut;");
eng.eval("Xe = simOut.Xe;”);
or
eng.eval("t = get(simOut, ‘tOut’);");
eng.eval("Xe = get(simOut, ‘Xe’);”);
For detailed documentation on accessing property values of an object in MATLAB, refer to the following link:

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by