tic;
for i=1:20
toc
disp('test');
java.lang.Thread.sleep((i-toc)*1000);
end
["test" removed for compactness]
Elapsed time is 0.008428 seconds.
Elapsed time is 1.000497 seconds.
Elapsed time is 1.999536 seconds.
Elapsed time is 2.999586 seconds.
Elapsed time is 4.000012 seconds.
Elapsed time is 4.999816 seconds.
Elapsed time is 5.999633 seconds.
Elapsed time is 6.999679 seconds.
Elapsed time is 7.999731 seconds.
Elapsed time is 8.999758 seconds.
Elapsed time is 9.999807 seconds.
Elapsed time is 10.999854 seconds.
Elapsed time is 11.999904 seconds.
Elapsed time is 12.999952 seconds.
Elapsed time is 13.998999 seconds.
Elapsed time is 14.999047 seconds.
Elapsed time is 15.999100 seconds.
Elapsed time is 16.999148 seconds.
Elapsed time is 17.999193 seconds.
Elapsed time is 18.999260 seconds.
Best Answer