run a for loop for 240 minutes
2 次查看(过去 30 天)
显示 更早的评论
Allow a foor loop to be run for 240 minutes.
0 个评论
回答(1 个)
Bora Eryilmaz
2022-12-14
编辑:Bora Eryilmaz
2022-12-14
% 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 个评论
Bora Eryilmaz
2022-12-19
You can use the tic/toc commands within the while loop:
tic
% Do stuff
elapsedTime = toc
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!