フィルターのクリア

Have time object start and stop at a specific time

1 回表示 (過去 30 日間)
Inna Pelloso
Inna Pelloso 2022 年 12 月 1 日
編集済み: Inna Pelloso 2022 年 12 月 1 日
Hi,
I have a timer object, tmr:
%%my_timer_test
tmr = timer ...
( 'Name' , 'my_timer' ...
, 'TimerFcn' , @(~,~) my_script ...
, 'BusyMode' , 'drop' ...
, 'ExecutionMode' , 'fixedDelay' ...
, 'Period' , 600 ...
, 'StartDelay' , 1 ...
);
and a script, my_script.m:
%%my_script
disp(datestr(now,31))
How can I modfify the timer, so that it starts at 0900, fires every 10 minutes (600 seconds), and stops firing at 1200?
Any help would be appreciated!
IP
  2 件のコメント
Rik
Rik 2022 年 12 月 1 日
Should it restart itself the next day?
Inna Pelloso
Inna Pelloso 2022 年 12 月 1 日
編集済み: Inna Pelloso 2022 年 12 月 1 日
I will be starting Matlab with a crontab each day around 0800, and want the time object start at 0900, fire at 10 minute intervals, with the final firing at 1200.

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

採用された回答

Rik
Rik 2022 年 12 月 1 日
You need to set the delay depending on the time that the timer object is created. The number of calls can be either calculated or set.
x = datetime("now");
StartDelay = seconds( datetime([year(x) month(x) day(x) 19 0 0])-x );
% You can also hard-code this to 19 if you prefer.
NumberOfCalls = numel(datetime([0 0 0,9 0 0]):duration(0,10,0):datetime([0 0 0,12 0 0]));
tmr = timer ...
( 'Name' , 'my_timer' ...
, 'TimerFcn' , @(~,~) my_script ...
, 'BusyMode' , 'drop' ...
, 'ExecutionMode' , 'fixedDelay' ...
, 'Period' , 600 ...
, 'TasksToExecute', NumberOfCalls ...
, 'StartDelay' , StartDelay ...
);
  1 件のコメント
Inna Pelloso
Inna Pelloso 2022 年 12 月 1 日
編集済み: Inna Pelloso 2022 年 12 月 1 日
This function: startat(t,firingTime), allows you specify the specific time to execute the timer, and is precsely what I'm looking for!
Appreciate your help!
IP

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by