matlab simulink simstate issue

조회 수: 10 (최근 30일)
matta karczewski
matta karczewski 2018년 5월 1일
댓글: Jim Riggs 2018년 5월 1일
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.

답변 (1개)

Jim Riggs
Jim Riggs 2018년 5월 1일
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
Jim Riggs
Jim Riggs 2018년 5월 1일
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
Jim Riggs 2018년 5월 1일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Using MATLAB Projects in Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by