MATLAB Answers

0

Loop with Fixed time

How can I make the loop with fixed time?
For example:
for i=1:5
 somecode;
end
I want to make every calculation time of the loop is about 1 sec And the total calculation time is about 5 sec

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Azzi Abdelmalek
on 3 Feb 2013
 Accepted Answer

for i=1:5
%somecode;
pause(1-tw) % tw is your computing time
end
%to find your computing time use tic and toc

  2 Comments

Jan
on 5 Mar 2013
The Java sleep() timer is more accurate: see http://undocumentedmatlab.com/blog/pause-for-the-better/. A timer might be even more precise.

Sign in to comment.