how to set a loop to calculate time
Show older comments
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.
Accepted Answer
More Answers (1)
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
1 Comment
Eyad Alkhotani
on 23 Mar 2022
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!