I am running a loop of 300 iterations. Within the loop, I have a logic statement as follows.
for i = 1:300
if arrival <1
Ai = Ai + ia_time(i);
else
arrival = ia_time(i-1);
Ai = ia_time(i) + arrival;
end
disp(Ai);
end
disp(Ai);
While the loop is open, 'disp(Ai)' prints the values correctly. However, if I attempt to use or print the variable after the final closing 'end', I only get the one final value of Ai. What I would like is an array of all values that I can reuse for future operations later in the code. I feel like it is not creating the array properly, and perhaps I need to assign the value of Ai to another variable as the loop iterates, but I can't seem to make that work either.
I know this should be simple, but I am beating my newbie head on the desk.
1 Comment
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/361580-how-do-i-properly-append-to-an-array-within-a-loop#comment_493509
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/361580-how-do-i-properly-append-to-an-array-within-a-loop#comment_493509
Sign in to comment.