Matlab练习:timer(定时器)
前言
某位同學(xué)畢設(shè)需要時(shí)間精確同步,因此,拜托我寫一個(gè)定時(shí)產(chǎn)生信號(hào)的程序,要學(xué)就學(xué)扎實(shí),因此順便就把matlab 里面timer的文檔給看了一遍。
正文
一下是help timer的內(nèi)容,將對(duì)此進(jìn)行分析,配合例子去理解效果更好哦
MATLAB Timer Object Properties and Methods.時(shí)間對(duì)象的屬性AveragePeriod - 平均執(zhí)行周期BusyMode - Action taken when TimerFcn executions are in progress.當(dāng)時(shí)間函數(shù)執(zhí)行過(guò)程中采取的動(dòng)作ErrorFcn - Callback function executed when an error occurs.錯(cuò)誤發(fā)生時(shí)的回掉函數(shù)ExecutionMode - Mode used to schedule timer events.時(shí)間事件的調(diào)度方式InstantPeriod - Elapsed time between the last two TimerFcn executions. 兩個(gè)時(shí)間函數(shù)執(zhí)行的間隔Name - Descriptive name of the timer object.定時(shí)器對(duì)象的名字Period - Seconds between TimerFcn executions.定時(shí)間執(zhí)行間隔Running - Timer object running status.定時(shí)器運(yùn)行狀態(tài)StartDelay - Delay between START and the first scheduled TimerFcn execution.定時(shí)器函數(shù)開(kāi)始和第一次調(diào)度之前的延遲。StartFcn - Callback function executed when timer object starts.定時(shí)器對(duì)象開(kāi)始時(shí)的回調(diào)對(duì)象StopFcn - Callback function executed after timer object stops.定時(shí)器結(jié)束時(shí)的回調(diào)函數(shù)Tag - Label for object.定時(shí)器對(duì)象的標(biāo)簽TasksToExecute - Number of times to execute the TimerFcn callback.定時(shí)器函數(shù)執(zhí)行的次數(shù)TimerFcn - Callback function executed when a timer event occurs.定時(shí)器事件發(fā)生時(shí)執(zhí)行的函數(shù)Type - Object type.對(duì)象類型UserData - User data for timer object.時(shí)間對(duì)象使用者的數(shù)據(jù)。timer methods:定時(shí)器方法Timer object construction:定時(shí)器對(duì)象創(chuàng)建@timer/timer - Construct timer object.創(chuàng)建定時(shí)器對(duì)象Getting and setting parameters:獲得或者設(shè)置定時(shí)器參數(shù)get - Get value of timer object property.得到定時(shí)器對(duì)象的屬性set - Set value of timer object property.設(shè)置定時(shí)器對(duì)象的屬性。General:通用方法delete - Remove timer object from memory.刪除display - Display method for timer objects.展示inspect - Open the inspector and inspect timer 觀察者 object properties.對(duì)象屬性isvalid - True for valid timer objects.合法嗎?length - Determine length of timer object array.定時(shí)器對(duì)象矩陣的長(zhǎng)度size - Determine size of timer object array.定時(shí)器對(duì)象的尺寸timerfind - Find visible timer objects with specified 找到定時(shí)器 找到特定的可視化定時(shí)器 property values.對(duì)象屬性 timerfindall - Find all timer objects with specified property values.找到所有具有特定值的定時(shí)器Execution:執(zhí)行start - Start timer object running.開(kāi)始定時(shí)器startat - Start timer object running at a specified time.在特定時(shí)刻開(kāi)始定時(shí)器stop - Stop timer object running.停止定時(shí)器運(yùn)轉(zhuǎn)wait - Wait for timer object to stop running.等待定時(shí)器停止運(yùn)轉(zhuǎn)例子
1一個(gè)每隔0.1秒,輸出一次y值的程序,總共輸出20次
y=0.1 t=timer('Timefcn','disp(y);','Period',0.1,'ExcutionMode','fixedSpacing','TasksToExcute',10) start(t)解釋一下,第一個(gè)選項(xiàng)時(shí)回調(diào)函數(shù),輸出y值,第二個(gè)選項(xiàng)是周期0.1,第三個(gè)選項(xiàng)是執(zhí)行模式,停靠,第四個(gè)是執(zhí)行次數(shù),10
2輸出一個(gè)δ(t)δ(t)函數(shù),即t時(shí)刻以前是0,t時(shí)刻以后是1,時(shí)間間隔依舊是0.1,輸出時(shí)間為10s。
x=0;
y=1;
td=3;
t1=timer(‘Timefcn’,’disp(x);’,’Period’,0.1,’ExcutionMode’,’fixedSpacing’,’TasksToExcute’,td*10)
t2=timer(‘Timefcn’,’disp(y);timer(‘Timefcn’,’disp(y);’,’Period’,0.1,’ExcutionMode’,’fixedSpacing’,’TasksToExcute’,(10-td)*10,‘StartDelay’,td*10)
start(t1)
start(t2)
這個(gè)start的順序不影響執(zhí)行時(shí)間,這個(gè)代碼本身執(zhí)行是很快的。
參考:
mathwork官方文檔
總結(jié)
以上是生活随笔為你收集整理的Matlab练习:timer(定时器)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 基本操作:win10系统磁盘分区
- 下一篇: postman提取返回值_postman