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

10 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Geoff Hayes
Geoff Hayes il 4 Ago 2019
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.

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by