This is a simple stopwatch GUI. It uses the functions CLOCK and ETIME along with user inputs to display the elapsed time in a HH:MM:SS.SSS format.
1) Press the START button to begin the timer (or press any key except L, R, or X)
a. If the timer has already been activated, press the PAUSE button to stop the timer (or press any key except L, R, or X)
b. If the timer has been paused, press the RESUME button to continue from the paused time (or press any key except L, R, or X)
c. If the timer is in lap mode, press the RESUME button to continue as though the lap time had not been activated (or press any key except L, R, or X)
2) Press the LAP button to view lap times (or press the L key)
a. The LAP button can be pressed successively to view mulitple laps
3) Press the RESET button to restore the timer (or press the R key)
4) Press the EXIT button to close the timer window (or press the X key)
Help notes available.
This file works great for timing myself speed solving the Rubik's Cube. :)
1. This file has been reworked to use nested functions and a timer rather than persistent variables. This allows the user to run multiple independent instances.
2. I also included the capability to start the stopwatch with a time offset. The offset can be positive or negative. If it is negative, the stopwatch will work like a countdown (see examples).
3. It is also possible to initialize the stopwatch with a 6 element vector in CLOCK format, which will cause the stopwatch to start running as soon as it is called (see examples).
% start the stopwatch
% start the stopwatch with a positive offset
% count down from one hour
% start the stopwatch with time already running
% start the stopwatch with running time since the day began
time = clock;
time(4:6) = 0;
% count down the time until midnight
time = clock;
time(3:6) = [time(3)+1 0 0 0];
Joseph Kirk (2020). Stopwatch (https://www.mathworks.com/matlabcentral/fileexchange/12628-stopwatch), MATLAB Central File Exchange. Retrieved .
Very helpful utility.
But multiple instances don't start until 'CTL+C' is pressed on the keyboard (which itself gives an error).
stopwatch(clock) --- when called four times for instance, will not display any clock until 'CTRL+C' is done manually at the keyboard.
Where to tweak in the code so that no keyboard intervention is required and no keypress is required and the multiple timers simply start running by calling 4 instances of stopwatch(clock) simultaneously ?
Thanks a lot!
LOVE it -- need to start with negative time to time Toastmasters speeches, but continue to be able to tell them how much they went over. Lap timer wonderful for sub-speech breakdowns.
Where is the code of stopwatch? I couldn't find it
thanks ... it has been very useful
Very nice work!
But I have a question. I want to add this function into a GUI and I want, everytime I press a specific pushbutton, to store the exact timestamp (so basically the time I push the button) to a buffer. Any help as to how to do that? I know I have to add code to the callback function of the pushbutton, but I am not sure exactly what to write. Thank you in advance.
Wow good work
Very useful.. i'm working in an image acquisition gui, and i was about finish.. then i realized, that some people in the lab may need to know when the study is over or the elapsed time of the test.. Thanks to your gui, i can use some of your programming to finish my work on time!!
Thank you very much Joseph!
I added some useful coding into program.. working nice..
i love it
I reworked this clock to use nested functions and a timer rather than persistent variables. Now multiple instances of the stopwatch can be running simultaneously and independently, and users don't have to close the figure window to work on other things.
I also added some new functionality, including:
(1) the ability to "seed" the stopwatch with a (positive or negative) time offset. A negative offset will cause the stopwatch to function like a countdown (see examples), and
(2) the ability to initialize the stopwatch with a 6 element vector in CLOCK format to count down to (or up from) a fixed date/time. In this mode, the stopwatch will begin running as soon as it is called (see examples).
Hello there. Great job, Joseph Kirk. Your program gives me an idea on how to measure a time spent in the program with beautiful GUI.
My intention is to write a file that can log presence of data as a time series like for example, x(t). I am trying to write a program to generate random circles and the program can record a time stamp for each location (x-y coordinates). I think it is possible but still struggling on how to do it. Please kindly give me some hints or advices.
Thank you again for your stopwatch,
How can I swith this function to script?Thanks
Kevin - Excellent idea. I'll see what I can do
Very nice. Great useful stopwatch. It would be great if the author can expand this to have multiple stopwatches on the window.
Very good. Nice display, easy to use, and no problems that I saw.
Jos: I appreciate your comments. I made the changes as you suggested and added lap-time functionality. :)
1) make it a function
2) provide a proper help section
3) format the output nicely using fprintf, so that when even I finally solves the rubic cube, I
don't get answers like elapsed-time = 372837482.3590
tic;pause;toc + enter solves the typing issue ...
Some people may not find this function useful, but it is perfectly suitable for some types of timing events.
I use it for repeated attempts to speed solve the Rubik's Cube. Solving a cube (usually) requires two hands, so having to type in 'toc' would add undesirable seconds to the time. It is much more efficient to tap the spacebar when the cube is solved. :)
Granted, MATLAB has much more productive uses than this, but this is the best system I have been able to come up with for timing events that require 2 hands. Perhaps there are others who could use it as well.
Even with the addition of useful help, is this of any value?
To execute this function, you must type the function name (stopwatch) followed by a carriage return. Then any keypress to start timing, then another keypress to stop it. This takes a total of 12 keystrokes.
Simply typing tic (then carriage return) to start timing, and then toc (and another carriage return) to stop timing takes a total of 8 keystrokes.
I don't see where stopwatch gains anything.
Wow, a real stopwatch for $1000 !
What about lap-times?
Sorry, but this is really too simple. Moreover, it is not a function, and does not contain useful help.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!