?? timer.txt
碼:
function timertest
%例:timer實現多線程
%作者:nostalgica
%我的Blog: nostalgica.blogcn.com
t = timer('TimerFcn',{@mycallback,'Hello Matlab!'}, 'Period', 1,'stopfcn',{@stopcallback,'Stopped!'},'TaskstoExecut',10,'execution','fixedRate');
start(t);
timestart=clock;
while(1)
if etime(clock,timestart)>=11%主線程約11s,timer設了10s,主線程多運行一會兒。
break;
end
pause(.5);%要是不pause,Timer線程搶不到啊!!
disp(['主線程: ' datestr(clock)]);
end
stop(t);
disp(['總共運行時間:' num2str(etime(clock,timestart))]);
function mycallback(obj, event,string_arg)
txt1 = 'Timer線程';
txt2 = string_arg;
event_type = event.Type;
event_time = datestr(event.Data.time);
msg = [ txt1 '(' event_type '):' event_time];
disp(msg);
function stopcallback(obj, event,string_arg)
txt2 = string_arg;
disp(txt2);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -