필터 지우기
필터 지우기

How to make any loop in a matlab to be executed 25 times per second

조회 수: 1 (최근 30일)
srinivasa poram
srinivasa poram 2012년 7월 4일
Hi, is there any method by which user can control the execution time of a loop orcode written in matlab script. I want a block code or while loopto be executed 25 times per second.
  댓글 수: 2
Daniel Shub
Daniel Shub 2012년 7월 4일
Do you want approximately 1/25 of a second between the events, or can you have the event happen 25 times in a row as quickly as possible and then wait for a second?
srinivasa poram
srinivasa poram 2012년 7월 4일
yes i need 1/25 of second between the events.

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

답변 (2개)

Walter Roberson
Walter Roberson 2012년 7월 4일
Create a timer() object whose callback invokes the code.
You will need to decide what you want done if, for whatever reason, an event would be late: do you want it to start anyhow (possibly making the next event late), or do you want to wait for the next interval.
(For example, if MS Windows decides that it is time to check for new security updates, then the resulting disk and network activity might be enough to delay execution of MATLAB more than 1/25th of a second, so then what?)

Jan
Jan 2012년 7월 4일
A very cheap approach, but perhaps this is enough:
iclock = clock;
while 1
disp(clock);
pause(0.04 - etime(iclock, clock)); % *Not* CPUTIME!
iclock = clock;
end
This does not crash, when the time required for processing the event exceeds 0.04 seconds, but pause(-0.2) is left as soon as possible.
Consider Walter's important arguments. I'd prefer the timer also, but this loop might be enough already.

카테고리

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