Creating a Countdown Timer in MATLAB

  • MATLAB
  • Thread starter amazingzuc
  • Start date
  • Tags
    Matlab Timer
In summary, the conversation is about creating a countdown timer for a MATLAB class using the tic and toc functions. The code provided includes a while loop and a function called labtimer. The loop is used to track the elapsed time and display the countdown.
  • #1
amazingzuc
1
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?
 
Physics news on Phys.org
  • #2
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
 

Related to Creating a Countdown Timer in MATLAB

What is a countdown timer in MATLAB?

A countdown timer in MATLAB is a tool that allows you to measure and display the remaining time in a specific task or event. It is commonly used in scientific experiments, presentations, and games to create a sense of urgency or to track progress.

How do I create a countdown timer in MATLAB?

To create a countdown timer in MATLAB, you can use the "timer" function. This function takes in the desired countdown duration and a function to be executed when the timer reaches zero. You can also customize the display of the timer using different formatting options.

Can I pause and resume the countdown timer in MATLAB?

Yes, you can pause and resume a countdown timer in MATLAB using the "pause" and "resume" functions. These functions allow you to temporarily stop the timer and continue it from where it left off.

How can I change the font and color of the countdown timer in MATLAB?

You can change the font and color of the countdown timer in MATLAB by using the "set" function. This function allows you to specify the properties of the timer, such as font size, font color, and background color.

Is it possible to have multiple countdown timers running simultaneously in MATLAB?

Yes, it is possible to have multiple countdown timers running simultaneously in MATLAB. You can create and manage multiple timers using different variable names and execute them simultaneously using the "start" function.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
10K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
225
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
17
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
10K
Back
Top