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

3 visualizaciones (últimos 30 días)
Sam Demidenko
Sam Demidenko el 15 de Nov. de 2021
Editada: Adam Danz el 17 de Nov. de 2021
t1=datetime('now');
tstart=('16-Nov-2021 11:20:00')

Respuesta aceptada

Adam Danz
Adam Danz el 15 de Nov. de 2021
Editada: Adam Danz el 17 de Nov. de 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 comentarios
Adam Danz
Adam Danz el 15 de Nov. de 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
Adam Danz el 15 de Nov. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Clocks and Timers en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by