Run a loop every hour regardless of its calculation time!

9 visualizzazioni (ultimi 30 giorni)
Hi All
I want to run a look evey hour and do some math inside the loop.
one solusion is to use tic/toc to get the math time and deduce it from the pause time, but I find it not efficient.
Any solusion to this?
Thanks.
  1 Commento
Stephen23
Stephen23 il 16 Ago 2019
Modificato: Stephen23 il 16 Ago 2019
Using tic / toc in a while loop is not very efficient.
Much better to use a timer object.

Accedi per commentare.

Risposta accettata

KALYAN ACHARJYA
KALYAN ACHARJYA il 23 Mar 2019
Modificato: KALYAN ACHARJYA il 23 Mar 2019
while true
tic
% some math here
elapsedTime=toc
pause(3600+elapsedTime);
clearvars elapsedTime;
end
% Please note on while loop to avoid infinite run
  3 Commenti
Walter Roberson
Walter Roberson il 15 Ago 2019
I would expect 3600-elapsedTime not 3600+elapsedTime
Bruno Luong
Bruno Luong il 16 Ago 2019
Use timer is much better. I think PAUSE will lock completely 99% of MATLAB.

Accedi per commentare.

Più risposte (1)

Walter Roberson
Walter Roberson il 15 Ago 2019

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by