run a for loop for 240 minutes
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Allow a foor loop to be run for 240 minutes.
0 Kommentare
Antworten (1)
Bora Eryilmaz
am 14 Dez. 2022
Bearbeitet: Bora Eryilmaz
am 14 Dez. 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
minutes(tf-ti) % Should be the same as T (in minutes)
But you can't rely on this for precise timing.
2 Kommentare
Bora Eryilmaz
am 19 Dez. 2022
You can use the tic/toc commands within the while loop:
tic
% Do stuff
elapsedTime = toc
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!