필터 지우기
필터 지우기

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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by