How do I start a function at the exact computer clock time?

1 view (last 30 days)
t1=datetime('now');
tstart=('16-Nov-2021 11:20:00')

Accepted Answer

Adam Danz
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
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.

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!