How to save Timer execution time

11 ビュー (過去 30 日間)
Jun Hao
Jun Hao 2014 年 9 月 22 日
コメント済み: Adam 2014 年 9 月 22 日
I create a Timer function, and I set the TImer to be executed 10 times. When the Timer running, how can I save the 10 execution time to workspace?
function t = Showmylove2MatlabTimer(~,thisEvent)
seconds2Show = 0.01;
totalTimes = 10;
t = timer;
t.UserData = seconds2Show;
t.StartFcn = @bbb;
t.TimerFcn = @(g,~)mylove2Matlab;
t.StopFcn = @blablabla;
t.Period = 0.002;
t.StartDelay = 6;
t.TasksToExecute = totalTimes;
t.ExecutionMode = 'fixedSpacing';
end
function ExTime = mylove2Matlab(~,thisEvent)
n = 1000;
a = unidrnd(n);
b = unidrnd(n);
s = a + b;
ExTime = thisEvent.Data.time;
disp(['I really love Matlab for ' num2str(s) ' years']);
disp(['Time is ' datestr(thisEvent.Data.time, 'dd-mmm-yyyy HH:MM:SS.FFF')]);
end
In this example, I want to save ExTime to workspace every time the function ExTime = mylove2Matlab to be executed. Thank you for your time and answer.

回答 (1 件)

Adam
Adam 2014 年 9 月 22 日
Can you not just use t.StopFcn to add the elapsed time to an array of timer values if you pass this array into the StopFcn?
  2 件のコメント
Jun Hao
Jun Hao 2014 年 9 月 22 日
you mean if I do not use StopFcn I can get the 10 StartFcn execution time ?
Adam
Adam 2014 年 9 月 22 日
No, I mean that StopFcn exceutes every time the timer stops so within your StopFcn you can get hold of this time every time and add it to an ever-expanding or presized (to size 10) array of times.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by