フィルターのクリア

How to Execute statements in the script at scheduled time or defined date & time ?

3 ビュー (過去 30 日間)
Hi all,
It would be great help if anybody can tell me How to Execute statements in the script at scheduled time or defined date & time with in the script. for example
T1 = datetime('now'); % T1 is current date & time
a= 10;
b= 20;
c = a*b;
T2 = T1 + hours(1) % T2 is after 1 hour of T1 time
% when the time difference is 1 hour the fallowing statements should execute
d = 20;
e = 20;
f = d*e;
I have tried with " Timer function " and " while " all possible ways and finally asking for your kind help.

採用された回答

Geoff Hayes
Geoff Hayes 2019 年 8 月 4 日
nelapati - if you just want your timer callback to fire x seconds from now, then using the examples from Create object to schedule execution of MATLAB commands, you could do something like
function myTimerTest
hTimer = timer('TimerFcn', @myTimerCallback, 'ExecutionMode', 'SingleShot', 'StartDelay', 10);
start(hTimer);
while strcmp(get(hTimer, 'Running'), 'on')
fprintf('timer is still runnning...\n');
pause(1.0);
end
delete(hTimer);
function myTimerCallback(hObject, event)
d = 20;
e = 20;
f = d*e
end
end
The above code is saved to a file called myTimerTest.m. It will execute the code in the myTimerCallback function 10 seconds after the timer is started (see the value assigned to the StartDelay property). If you want to fire a callback an hour from when the myTimeTest function is called, you would change this value to 3600.
  1 件のコメント
Dhanaraj Nelapati
Dhanaraj Nelapati 2019 年 8 月 13 日
Thank you for your answer Geoff Hayes... I have solved the problem with timer function .

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

その他の回答 (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