matlab simulink simstate issue
11 views (last 30 days)
Show older comments
hi everyone,
I am trying to use Simstate to stop, save and reload my model in order to save my data a couple of times before the whole simulation is actually done.
I've tried using :
set_param('mysim','SaveFinalState','on','FinalStateName','myOperPoint','SaveCompleteFinalSimState','on');
sim('mysim','StopTime','10');
set_param('mysim','LoadInitialState','on','InitialState','myOperPoint');
sim('mysim','StopTime','20');
but it seems that the model save "myOperPoint" isn't getting saved if the model does not reach it's actual end.
Does anyone have a clue how to actually use this because the official tutorial isn't helping me much.
0 Comments
Answers (1)
Jim Riggs
on 1 May 2018
I notice the same thing. If I use this, then SimState is not saved:
set_param('mysim','SaveFinalState','on','FinalStateName','myOperPoint','SaveCompleteFinalSimState','on');
sim('mysim','StopTime','10');
but if I do this, then the SimState is saved:
set_param('mysim','SaveFinalState','on','FinalStateName','myOperPoint','SaveCompleteFinalSimState','on');
sim('mysim');
.
2 Comments
Jim Riggs
on 1 May 2018
I just tried the following, and it ran to the desired stop time and saved the SimState:
set_param('mysim','SaveFinalState','on','FinalStateName','myOperPoint','SaveCompleteFinalSimState','on');
set_param('mysim','StopTime','10');
sim('mysim');
Jim Riggs
on 1 May 2018
Whenever I build a Simulink model, I like to set the stop time to a parameter which is defined in the Matlab workspace, e.g.
set_param('mysim','StopTime','sim_StopTime');
So, when I run the model, I define the sim_StopTime parameter in a script, and then run the model. Using this method, the following worked for me:
set_param('mysim','SaveFinalState','on','FinalStateName','myOperPoint','SaveCompleteFinalSimState','on');
sim_StopTime = 10.0;
sim('mysim'); % SimState successfully saved
set_param('mysim','LoadInitialState','on','InitialState','myOperPoint');
sim_StopTime = 20.0;
sim('mysim'); % Sucessfully loaded the saved SimState and ran out to 20 seconds
See Also
Categories
Find more on Simulink Environment Customization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!