Hello all,
My question is: it is possible to change the timer's period inside the TimerFcn?
Thanks

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 16일

0 개 추천

This page mentions an approach to vary the period of timer: https://stackoverflow.com/questions/15576682/matlab-change-repeating-timer-period
Here I show the method mentioned in the second answer. This example sets a random time period between 1 to 5 seconds after each callback of timer.
t = timer('StartDelay', 1, 'TimerFcn', @timerFcn, ...
'StopFcn', @timerStopFcn, 'ExecutionMode', 'singleShot');
start(t);
function timerFcn(obj, ~)
disp(obj.StartDelay)
end
function timerStopFcn(obj, ~)
period = randi([1 5]);
obj.StartDelay = period;
start(obj);
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Code Execution에 대해 자세히 알아보기

제품

릴리스

R2015a

태그

질문:

2020년 4월 16일

답변:

2020년 4월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by