how to make a loop for a simulation?

9 次查看(过去 30 天)
Amir
Amir 2014-6-23
评论: A Jenkins 2014-6-27
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.

回答(3 个)

A Jenkins
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.)
____
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 个评论
Amir
Amir 2014-6-24
The problem is that its a real-time simulation and Im using GUI, there is only one button, the START button. I want the scope results to plot on the axes and I cant get any values if I dont pause the simulation, soooo this was supposed to be a trick, pause---plot---continue---pause---plot... so your answer doesnt really help me
A Jenkins
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
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?

Amir
Amir 2014-6-27
yes, cause the resaults should be displayed in the GUI axes and therefor the simulation needs to be paused, ploted in the axes and the continued....

类别

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