I want MATLAB to trigger an event at 8:00 AM tomorrow, how would I do that?

10 views (last 30 days)
This here is what I've got so far. Any help would be greatly appreciated.
t1 = datetime('now')
pause(2)
t2 = datetime('tomorrow')
if t2>t1
t1
else
t2
end
  1 Comment
Nathan Szondy
Nathan Szondy on 9 Dec 2020
Edited: Nathan Szondy on 9 Dec 2020
By the way, I'm using this to create an alarm clock using this code here, where I'm replacing the time4 variable with the time tomorrow:
i = 0;
time4 = 5;
for i = 1:1:time4
pause(1);
if i > 4
display('It is time to wake up');
talk('Dev1', 'ao0', 3.5);
pause(1);
talk('Dev1', 'ao0', 0);
end
end

Sign in to comment.

Answers (2)

Fangjun Jiang
Fangjun Jiang on 9 Dec 2020

Rik
Rik on 9 Dec 2020
You should use the timer class that Fangjun linked, but your approach is also possible:
t2 = datetime('tomorrow');
while true
pause(2)%check the time every two seconds
if datetime('now')>t2
disp('midnight has broken')
break
end
end
beep

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!