필터 지우기
필터 지우기

Is there a way to pause the tic timer (without resetting tic)?

조회 수: 31 (최근 30일)
Dc215905
Dc215905 2018년 2월 28일
답변: Dc215905 2018년 3월 1일
I would like to briefly pause the tic timer. I'm aware of pause() but that doesn't pause the stopwatch. I would like to start and stop (not reset) the stopwatch based on various conditions in my script.
Thanks,
David
  댓글 수: 2
Walter Roberson
Walter Roberson 2018년 2월 28일
Cannot be done with tic and toc, which just take real-time clock readings and subtract them.

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

답변 (3개)

Stephen23
Stephen23 2018년 2월 28일
편집: Stephen23 2018년 2월 28일

David Goodmanson
David Goodmanson 2018년 3월 1일
Hi David
Here is a very basic way to accomplish this, no extra structures or anything. It works for a series of tic...[do stuff]...tocc statements. You can save the overall result with x = tocc on the last one.
Since it's pretty simple, there are some limitations. For regular toc, if you do a tic followed by several tocs in a row, each toc gives the time from the initial tic statement. If you follow a tic by more than one tocc, then tocc gets hopelessly confused. So you could not have more than one tocc in a row, which is not the intent anyway.
You can combine this with regular tic and toc, but only sometimes. tocc just looks for the most recent instance of tic, so using toc as in (tic..tocc), (tic..toc) (tic..tocc) works, but a nested one (tic..tocc), (tic..(tic..toc)..tocc) doesn't.
function ac_t = tocc
% accumulated elapsed time between a series of tic and tocc statements.
% to reset, use 'clear tocc' any time before the first relevant tic statement.
%
% tocc is similar to toc in that
% the tocc command displays a result.
% the x = tocc command saves the result in variable x.
persistent t;
if isempty(t)
t = toc;
else
t = t + toc;
end
ac_t = t;
if nargout~=1
disp([' Total elapsed time for selected intervals is ',num2str(t),' seconds'])
end
end % function

Dc215905
Dc215905 2018년 3월 1일
Thank you for all of the suggestions! I'm going to test them out in my script and see what comes of it. I'll follow-up.
Cheers,
David

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by