- Schedule Command Execution Using Timer.
- Timer limitations which notes "Avoid using timer objects for real-time applications."
- To get clock time: clock
How do I start a function at the exact computer clock time?
7 views (last 30 days)
Show older comments
t1=datetime('now');
tstart=('16-Nov-2021 11:20:00')
0 Comments
Accepted Answer
Adam Danz
on 15 Nov 2021
Edited: Adam Danz
on 17 Nov 2021
> How do I start a function at the exact computer clock time?
It depends on how you define "exact" and "start".
If "start" means to evoke the function and if "exact" allows for several ms lag, you could use a timer to continually check the clock time at regular intervals and evoke the function as soon as the specified time is detected.
The minimum interval is 0.001 sec (1 ms) but you should expected small delays associated with runtime of the timer and other internal processing required to call your function. If Matlab is busy processing another task when the target clock time arrives, there could be additional delays.
Also see
2 Comments
Adam Danz
on 15 Nov 2021
Sam Demidenko's answer moved here as a comment
> Yes, evoke a function and 100mS is acceptable.
> Not sure how to create a wait loop, such that the programed time is not missed.
> Thank you
Adam Danz
on 15 Nov 2021
That's all done within the timer function.
Timers are a little confusing to set up if you haven't set one up before. I recommend going through the timer documentation and examples to start. Once you have a timer put together, if you still have questions, share the timer and I can help fill in the gaps.
More Answers (0)
See Also
Categories
Find more on Clocks and Timers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!