Varying timer's period inside the TimerFcn
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Amira chriki
le 16 Avr 2020
Réponse apportée : Ameer Hamza
le 16 Avr 2020
Hello all,
My question is: it is possible to change the timer's period inside the TimerFcn?
Thanks
0 commentaires
Réponse acceptée
Ameer Hamza
le 16 Avr 2020
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Code Execution dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!