how to set a loop to calculate time
4 次查看(过去 30 天)
显示 更早的评论
I'm trying to calculate time starting at 0.01 hrs and increasing by 1.1 until it reaches 24 hrs,
for i=1:83
t=0.01
t(i)=t(i)*1.1;
end
and I also need it to have a max value of 24 that the final time calculated even if it's more than 24 it comes back as 24.
0 个评论
采纳的回答
更多回答(1 个)
John D'Errico
2022-3-23
EVERY pass through your loop, you REDEFINE the variable t. Learn to use MATLAB. Stop thinking in terms of loops for everything.
t = 0.1:1.1:24;
t(end)
Note that, using this increment and start point, the last value of t will be 23.2, not 24. So are you saying that then you want to append one more element to the end of t?
if t(end) < 24
t(end + 1) = 24;
end
另请参阅
类别
在 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!