필터 지우기
필터 지우기

Can i get the remaining time from the start of a timer?

조회 수: 3 (최근 30일)
giacomo bruno
giacomo bruno 2016년 4월 22일
답변: Swaraj 2023년 2월 9일
Hi everyone, I was wondering if it was possible to get the amount of time that remains before a timer executes its TimerFcn? I have a very simple timer such as:
t = timer;
t.StartDelay = 300;
t.TimerFcn = @(myTimerObj, thisEvent)disp('300 seconds have elapsed');
start(t)
How can I know how many more seconds I have before the text appears? Thank you in advance
  댓글 수: 1
Adam Danz
Adam Danz 2019년 9월 14일
You can approximate time remaining by using tic/toc.
t = timer;
t.StartDelay = 300;
t.TimerFcn = @(myTimerObj, thisEvent)disp('300 seconds have elapsed');
t0 = tic();
start(t)
% to check time remaining
remainingTime = t.StartDelay-toc(t0);

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

답변 (1개)

Swaraj
Swaraj 2023년 2월 9일
You can use tic, toc and a while loop for this.
t = timer;
t.StartDelay = 20;
t.TimerFcn = @(myTimerObj, thisEvent)disp('20 seconds have elapsed');
sTime = tic;
start(t)
while (toc(sTime) < t.StartDelay)
fprintf('%.0f seconds remaining\n', t.StartDelay - toc(sTime));
pause(1);
end

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by