www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/StopTimerExample.m

    %% Stop Timer  
% Create a timer object that generates 100 random numbers and executes one
% million times. Define a |StopFcn| callback that displays the message 'Timer
% has stopped.' Start the timer and verify the timer is running 

% Copyright 2015 The MathWorks, Inc.

t = timer('TimerFcn','rand(100,1);',...
    'ExecutionMode','fixedSpacing','TasksToExecute',1e6,...
    'StopFcn','disp(''Timer has stopped.'')');
start(t)
t.Running
%% 
% Manually stop the timer and verify it is no longer running. Delete the timer. 
stop(t)
t.Running
delete(t)