How can I run a stopwatch in MATLAB and store time points in a variable by hitting a key on the keyboard?
3 次查看(过去 30 天)
显示 更早的评论
I am collecting a continuous recording from a sensor, but I will only need certain segments of the recording. I want to use a stopwatch in MATLAB to record the start and stop times of the relevant segments of data from the sensor. I need a function that starts a timer when I push one key, then stores the timer value when I press another key and that stops the timer when I press a third key. I was going to use the tic and toc functions . . . how do I get MATLAB to store the time elapsed since the last tic when I hit a certain key on the keyboard? Thanks!
1 个评论
Ngonidzashe Nedziwe
2017-5-19
编辑:Adam
2017-5-19
i would suggest reading through this previous post https://www.mathworks.com/matlabcentral/answers/262561-i-d-like-to-make-a-timer-or-stopwatch
回答(1 个)
Abhinav Gurram
2017-5-22
As you rightly mentioned, the use of ' tic ' and ' toc ' functions seem best suited for your workflow. You can use any of the ways listed here: Ways to build apps to build an app, and have corresponding buttons for starting(tic) and stopping(toc) the timer. Furthermore, the 'tic' function can be used along with a variable to record time for simultaneous time spans. The variable, 'timerVal', has a value that is equal to the value of the internal timer at the execution of the 'tic' command. The 'tic' function can now be called as:
>>timerVal = tic
Afterward, you can use the 'toc' function to capture the elapsed time since the 'tic' command corresponding to 'timerVal' as:
>>elapsedTime = toc(timerVal);
You can associate the variable, 'elapsedTime' with a particular callback function that is executed when a keyboard key is pressed. The 'KeyPressFcn' might be a good way to capture the user's keyboard input. You can visit the following link for more information on how to write callbacks for apps:
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!