Filter löschen
Filter löschen

TIme bound for loop

1 Ansicht (letzte 30 Tage)
Sreet Swastik
Sreet Swastik am 27 Mär. 2013
Is it possible for me to run a loop for a specified amount of time say 3 seconds?

Antworten (1)

Mark
Mark am 27 Mär. 2013
This isn't a for loop, but you can get something like what you describe using a while loop.
t = now;
secondsToWait = 3;
while true
if now >= t + secondsToWait/24/60/60
break;
end
% Here you can put what you want to run...
end
  2 Kommentare
Mark
Mark am 27 Mär. 2013
This isn't perfect because if you have something that takes a long time to run, it won't be stopped by the loop until after it is finished.
Walter Roberson
Walter Roberson am 27 Mär. 2013
Also, if you use "now" then you are going to be referring to clock seconds rather than cpu seconds.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by