Creating a Countdown Timer in MATLAB

  • Topic: MATLAB 
  • Thread starter amazingzuc
  • Start date
  • Tags Tags
    Matlab Timer
1 reply · 11K views · last reply
amazingzuc
Messages
1
Reaction score
0
Im trying to make a countdown timer for my MATLAB class using the tic and toc functions.
so far this is what I have:

function lab4program1
disp('Welcome to the countdown timer program');
done = false;
tic();
while ~done
time = input('Enter a time (seconds) or negative number to quit:');

****************************

disp(toc);


last_time = toc();
while (true)
elapsed_time = toc()-last_time
last_time = last_time+elapsed_time;
end

if done
disp('BLAST OFF!');
end

end


Can anyone help me with the loop that goes where the asterisks are?
 
Hi what about this

function labtimer
disp('Welcome to the countdown timer program');time = input('Enter a time (seconds) ');
tstart=tic; % store starting time
while time >1 % if counter is greater than 1

if (abs(toc(tstart)-1))<0.01 % if one second has elapsed

tstart=tic; % start timer again for next second
time=time-1; % reduce the time by one as one second has elapsed
disp(time) % display the counter
end

end
end