MATLAB 中的簡單計時器

以下是以固定間隔觸發的計時器。它的超時由 Period 定義,並在超時時呼叫 Timerfcn 定義的回撥。

t = timer;
t.TasksToExecute = Inf;
t.Period = 0.01; % timeout value in seconds
t.TimerFcn = @(myTimerObj, thisEvent)disp('hello'); % timer callback function
t.ExecutionMode = 'fixedRate';
start(t)
pause(inf);