MATLAB: Varying timer’s period inside the TimerFcnMATLABtimerHello all,My question is: it is possible to change the timer's period inside the TimerFcn?Thanks Best AnswerThis 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)endfunction timerStopFcn(obj, ~) period = randi([1 5]); obj.StartDelay = period; start(obj);end Related QuestionI keep getting this error Error: File: BarcodeRea​derLiveScr​ipt.m Line: 242 Column: 5 Illegal use of reserved keyword “else”.Stop timerInterrupt a timer wait functionHow to pause the execution of one timer while continuing to execute another timer in MATLAB 7.8 (R2009a)Timer Callback Function Variable periodTimer with varying periods
Best Answer