필터 지우기
필터 지우기

TIme bound for loop

조회 수: 1 (최근 30일)
Sreet Swastik
Sreet Swastik 2013년 3월 27일
Is it possible for me to run a loop for a specified amount of time say 3 seconds?

답변 (1개)

Mark
Mark 2013년 3월 27일
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
Mark
Mark 2013년 3월 27일
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 2013년 3월 27일
Also, if you use "now" then you are going to be referring to clock seconds rather than cpu seconds.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by