How to execute a piece of code if a condition is verified for 'n' seconds
Show older comments
Hi, i need to do something like this:
if (my_condition is verified for 'n' seconds) do_this_piece_of_code; end
However i don't want that the execution stops for 'n' seconds when arrives there to evaluate the condition, but i want that anywhere the execution is, if that condition is verified for 'n' seconds, execute that piece of code. imho i need to write it out of my program.
Could you help me? Thanks in advance
2 Comments
Oleg Komarov
on 17 Apr 2012
You need to add more details, what is your condition?
There are several ways to do that: timer, simple double condition that checks time, while condition...
raffaele
on 17 Apr 2012
Answers (2)
Sean de Wolski
on 17 Apr 2012
Sounds like you will inevitably want timers at some point:
doc timer
You might get lucky and be able to use tic/toc though
doc tic
doc toc
raffaele
on 18 Apr 2012
0 votes
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!