![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175147/image.png)
how to make a loop for a simulation?
조회 수: 4 (최근 30일)
이전 댓글 표시
I've made a simulink model and I want the simulaltion after starting it to go into a loop that will pause (plot) and then continue the simulation. Can anybody help me with this?
set_param('modelZaGui1','SimulationCommand','start');
go into loop----------
set_param('modelZaGui1','SimulationCommand','pause'); % pause after 10 seconds
plot ( )
set_param('modelZaGui1','SimulationCommand','continue');
set_param('modelZaGui1','SimulationCommand','pause'); % pause after 10 seconds
plot ( )
and to go like this to the end of the simulation. Simulation time is 1000 and it should pause and plot after ever 10 seconds.
댓글 수: 0
답변 (3개)
A Jenkins
2014년 6월 24일
1) This is kind of awkward. Is there a reason you can't use the built in "Scope" block to accomplish this?
2) If you must do it this way, I suppose you could use the "Assertion" block to pause the simulation as described in the help for Controlling Execution of a Simulation. Add a modulus calculation to get "every 10 seconds". (Example model attached.)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175147/image.png)
____
Your main loop could then just wait for the simulation to pause, then call plot, etc, until the simulation is stopped.
%init so they have some value at t==0
ScopeData.time=[];
ScopeData.signals.values=[];
set_param(bdroot,'SimulationCommand','start')
% outer loop for the full simulation
while ~strcmp(get_param(bdroot,'SimulationStatus'),'stopped')
pause(.001) % give the plot a chance to update
if strcmp(get_param(bdroot,'SimulationStatus'),'paused')
plot(ScopeData.time,ScopeData.signals.values);
set_param(bdroot,'SimulationCommand','continue')
end
end
댓글 수: 2
A Jenkins
2014년 6월 24일
Please clarify why this doesn't help? This runs the model and updates the plot every 10 seconds per your specifications.
Kaustubha Govind
2014년 6월 27일
It seems like you can achieve the same result by using a Scope block with a Decimation factor of 10. Is there a reason you want to use PLOT instead?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!