run a for loop for 240 minutes

2 visualizaciones (últimos 30 días)
Momen AlManaseh
Momen AlManaseh el 14 de Dic. de 2022
Comentada: Bora Eryilmaz el 19 de Dic. de 2022
Allow a foor loop to be run for 240 minutes.

Respuestas (1)

Bora Eryilmaz
Bora Eryilmaz el 14 de Dic. de 2022
Editada: Bora Eryilmaz el 14 de Dic. de 2022
% Runs for 5 seconds (i.e., 5/60 minutes)
T = 5/60; % minutes
ti = datetime('now');
tf = datetime('now');
while (minutes(tf-ti) < T)
% Do stuff
% Update current time
tf = datetime('now');
end
seconds(tf-ti) % Should be the same as T (in seconds), or
ans = 5.0000
minutes(tf-ti) % Should be the same as T (in minutes)
ans = 0.0833
But you can't rely on this for precise timing.
  2 comentarios
Momen AlManaseh
Momen AlManaseh el 16 de Dic. de 2022
execusme sir, do you have any idea how i can computer the elapsed time in each iteration in for loop ?
Bora Eryilmaz
Bora Eryilmaz el 19 de Dic. de 2022
You can use the tic/toc commands within the while loop:
tic
% Do stuff
elapsedTime = toc
elapsedTime = 0.0036

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by