Varying timer's period inside the TimerFcn

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

 采纳的回答

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by