Using a timer to execute a function
조회 수: 9 (최근 30일)
이전 댓글 표시
Jeff VanKerkhove
2015년 2월 19일
편집: Giorgos Papakonstantinou
2015년 2월 19일
So, I have a timer and I want to use the time to trigger an event. That is, at a certain time, I want a function (called OnFunc) to be executed.
when time_value == 10
OnFunc();
end
Is there a function analogous to a 'when' statement that can execute a command when the time reaches a certain point?
댓글 수: 0
채택된 답변
Giorgos Papakonstantinou
2015년 2월 19일
편집: Giorgos Papakonstantinou
2015년 2월 19일
A simple timer:
t = timer('BusyMode', 'Drop', ...
'ExecutionMode', 'fixedDelay', ...
'StartFcn', [], ...
'TimerFcn', @(obj, evd) disp('hallo'), ...
'StopFcn', [], ...
'Period', 2);
Issue start(t) to start the timer and stop(t) to stop it.
This timer executes the timer function @(obj, evd) disp('hallo') every 2 seconds. If the execution of the TimerFcn has not completed before the next execution, then the timer will Drop the next execution.
You can create your own callback for your TimerFcn.
At the end issue
delete(t)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Counter and Timer Input and Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!