필터 지우기
필터 지우기

Saving/Loading the SimState Programmatically

조회 수: 8 (최근 30일)
Benjamin
Benjamin 2011년 2월 21일
I have a problem with saving/loading SimState programmatically. It works when i do it manually in the Simulink settings, but when doing it in a m file i get an error. My code is simply
simfile = 'simfile';
set_param(simfile, 'SaveFinalState', 'on', 'FinalStateName','SimState','SaveCompleteFinalSimState', 'on');
set_param(simfile, 'LoadInitialState', 'off');
simOut = sim(simfile,'StopTime',num2str(10));
set_param(simfile, 'SaveFinalState', 'off');
set_param(simfile, 'LoadInitialState', 'on', 'InitialState','SimState');
simOut = sim(simfile,'StopTime',num2str(20));
resulting in an error
??? Error using ==> simtest at 10
Error evaluating expression 'SimState' for 'Initial state' specified in the Configuration Parameters dialog for block diagram 'simfile': Undefined function or variable
'SimState'.
What am i missing?
Thanks :)
Benjamin

채택된 답변

Benjamin
Benjamin 2011년 2월 21일
Thanks for quick response :)
I changed the code into simOut = sim(simfile,'StopTime',num2str(10),'SaveFinalState','on','FinalStateName','SimState','SaveCompleteFinalSimState', 'on'); simOut = sim(simfile,'StopTime',num2str(20),'SaveFinalState', 'off','LoadInitialState', 'on', 'InitialState','SimState');
which works. I didn't get your answer though. I thought the string you questioned, made that the mdl file called 'simfile.mdl' save the final values under the name 'SimState'. And these states are then loaded later. What am i misunderstanding?
Thanks again :)
  댓글 수: 3
Paulo Silva
Paulo Silva 2011년 2월 21일
btw thanks for posting your code, it might be useful for other like me.
Benjamin
Benjamin 2011년 2월 21일
You're welcome :)
Ben

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

추가 답변 (1개)

Ronald Verhoeven
Ronald Verhoeven 2011년 2월 26일
I have exactly the same problem. I didn't get the answer yet. Who could help me solving the above posted question? Thank you.
  댓글 수: 1
Benjamin
Benjamin 2011년 2월 28일
For the record: I forgot to mention, that the assignin() function is needed to assign xFinal into the workspace, if the sim() function is called from within a function.

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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by