Count the time a toggle button is pressed down

조회 수: 6(최근 30일)
Matt
Matt 2014년 12월 2일
댓글: Andrew Reibold 2014년 12월 2일
Hello,
I would like to know how can I create a timer that will only be activated when a toggle button is pressed down. It will of course start from 0 as the button is up when I launch the GUI, but when I press the button, I would like the timer to start, and then stop when I press it again. Then, I would like the timer to resume when I press the toggle button down again, and so on.
How can I do that?
Thanks!

답변(1개)

Andrew Reibold
Andrew Reibold 2014년 12월 2일
편집: Andrew Reibold 2014년 12월 2일
I use tic and toc to start and stop timers
>> help tic
tic Start a stopwatch timer.
tic and TOC functions work together to measure elapsed time.
Run tic and a timer starts. Then everytime you run toc , it tells you how much time since the last tic.
What I would do is run tic and toc to measure how long the toggle was down. Save that value to a variable. Then each time you do that another time, add the new tic/toc difference to your running variable of total time.
  댓글 수: 3
Andrew Reibold
Andrew Reibold 2014년 12월 2일
Nice Guillaume.
Any updates Matt..?

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by