how can i stop simulation if it takes so long?

hi guys how can i stop simulation with a block or something else if time to complete the simulation takes so long.the simulation is part of a code and this must be automatic. thank you with regard

1 Comment

saman
saman on 24 Apr 2014
Edited: saman on 27 Apr 2014
guys.i finally can find a way.i used a block combination that takes count sample times.if my file works properly the counter doesn't reach the upper limit and if it works bad the counter reaches the upper limit. thank to my friend @the cyclist for his inspiring idea. at the first i got the clock signal and compared with zero.the boolean signal divided by itself and make a count to add the counter.you should use a memory block to add the signal of summation with the output of memory block that form a feedback system.the output of system divide by an integer.for my case i use 100.this is for avoiding reaching to upper bound of memory block buffer.and finally i compared the divide block with an integer.if the signal exceed the threshold the compare block send a signal to stop block. excuse me if my explanation wasn't good.my english isn't good. i apologize for my mistakes.

Sign in to comment.

 Accepted Answer

If your simulation has some kind of looping structure in it (e.g. for loop), then you could use the tic/toc functions something like this:
x = 0;
% Simulation starts here. (Using a while loop that is always true, to mimic a long-running simulation.)
tic
while true
x = x+1;
if toc > 5
break
end
end
last_x = x
This "simulation" will halt if it runs for more than about 5 seconds.

5 Comments

thanx how can i link real simulation time with this code?consider i run a .mdl file with the command 'sim x.mdl' and it runs. it takes too long. the code you have written place where?and how can we stop the simulation with your code? thanks very much
@thecyclist nice solution. And regarding the comment, tic-toc returns real passed time and not cpu time. However, are you telling that you do one call to a .mdl file and that the .mdl time takes too long time to run?
@saman: Sorry, I should have realized you were talking about a Simulink model. My solution was geared toward MATLAB.
@Patrik Ek yes.this is my problem.and i don't know how figure it out.is there anybody to now the solution?

Sign in to comment.

More Answers (1)

Magdi Mosa
Magdi Mosa on 10 Oct 2018
Edited: Magdi Mosa on 10 Oct 2018
yes thank you. it works well, for simplification the following picture may elaborate the idea

Categories

Find more on General Applications in Help Center and File Exchange

Asked:

on 21 Apr 2014

Edited:

on 10 Oct 2018

Community Treasure Hunt

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

Start Hunting!