However, in 'error' mode, when the queue is nonempty, the timer calls the function
that you specify using the ErrorFcn property, and then stops processing. The currently
running callback function completes, but the callback in the queue does not execute.
For example, modify mytimer.m (described in the previous section) so that it includes an
error handling function and sets BusyMode to 'error'.
function mytimer()
t = timer;
t.Period = 1;
t.ExecutionMode = 'fixedRate';
t.TimerFcn = @mytimer_cb;
t.ErrorFcn = @myerror;
t.BusyMode = 'error';
t.TasksToExecute = 5;
t.UserData = tic;
start(t)
end
function mytimer_cb(h,~)
timeStart = toc(h.UserData)
pause(1.6);
timeEnd = toc(h.UserData)
end
function myerror(h,~)
disp('Reached the error function')
end
This table describes how the timer manages the execution queue.
Approximate
Elapsed Time
(Seconds)
Action
0 Start the first execution of the callback.
1 Attempt to start the second execution of the callback. The first
execution is not complete, but the execution queue is empty. The
timer adds the callback to the queue.
27 Program Scheduling