# Does anyone know how to do this problem

3 views (last 30 days)
Ethan on 5 Nov 2014
Commented: David Sanchez on 5 Nov 2014
MATLAB has timing functions that allow your program to monitor how much time has elapsed. These are called tic and toc. The function toc returns the amount of time since the last tic. Use a while loop to do the following for a total of 4 seconds. Every 0.3 seconds print, using fprintf, the message “The elapsed time is:” followed by the elapsed time.
Geoff Hayes on 5 Nov 2014
Ethan - see tic and toc for details. Calling tic will start a stopwatch timer, and calling toc will return the elapsed time since the stopwatch timer was started. Note that toc can refer to a specific stopwatch timer. Pay particular attention to the third example given in the toc link.

David Sanchez on 5 Nov 2014
tic
lim = 0.3;
N=1;
while toc<.61
%%%%%
%%%%%
tmp = toc;
if tmp>lim
fprintf('The elapsed time is %g\n', tmp)
N=N+1;
lim=lim*N;
end
end
David Sanchez on 5 Nov 2014
obviously, you chane .61 by 4 to cover up your case
...
while toc < 4
...