Discussion:
Terminating a simulation if it is taking to long to complete
(too old to reply)
Arran
2006-08-29 14:09:15 UTC
Permalink
Is there a way to stop a simulation that has been started using the
sim command if the simulation is taking too long to complete? The
simulation is being run from an m file inside a loop.

I'm trying to optimise a model's parameters using a genetic
algorithm. I've set a minimum step size but there are certain
combinations of parameters that are causing the simulation to hang
without causing an error.

Thanks for your help
Scott Seidman
2006-08-29 14:16:58 UTC
Permalink
Post by Arran
Is there a way to stop a simulation that has been started using the
sim command if the simulation is taking too long to complete? The
simulation is being run from an m file inside a loop.
I'm trying to optimise a model's parameters using a genetic
algorithm. I've set a minimum step size but there are certain
combinations of parameters that are causing the simulation to hang
without causing an error.
Thanks for your help
Does control-C work?
--
Scott
Reverse name to reply
Carlos
2006-09-06 01:16:43 UTC
Permalink
I use a very, very crude solution. It is like this:
d=dir('stop.txt');
if ~isempty(d)
keyboard
end

so if I need to stop, simply create a file with the proper name and
sooner or later the program will pause.
Of course: the solution is appropriate if you place the piece of code
in a place which is not executed 100 times a second...
Regards
carlos
NZTideMan
2006-09-06 02:24:50 UTC
Permalink
I use waitbar inside the simulation loop:
hwait=waitbar(0,['Executing ' num2str(nrun) ' simulations......']);
for irun=1:nrun
waitbar(irun/nrun,hwait)
-
-
-
end
close(hwait)

Everytime waitbar updates the bar, you get a chance to Ctrl C and stop
the simulation.
Not very elegant, but it works..........
Lionel Broussard
2006-09-06 11:19:11 UTC
Permalink
Post by Arran
Is there a way to stop a simulation that has been started using the
sim command if the simulation is taking too long to complete? The
simulation is being run from an m file inside a loop.
I'm trying to optimise a model's parameters using a genetic
algorithm. I've set a minimum step size but there are certain
combinations of parameters that are causing the simulation to hang
without causing an error.
Thanks for your help
You can not stop a simulation after a sim command. If you want stop a
simulation running, you must start it using
set_param(bdroot,'simulationcommand','start') ant stop it using
set_param('vdp','simulationcommand','stop') or to press the stop
button from simulink. You can know the state of your simulation using
get_param('vdp','SimulationStatus').

For more information : <http://www.mathworks.com/support/tech-notes/1900/1903.html#13>

I hope this help you.

Best

Loading...