Reputation: 469
I have a series of results at the end a while loop. These results are not saved in an array but they are shown for esch loop. I want to copy all these results, that are created for each loop, in an array, in a list. For example
while(condition)
do something
if(condition)
a=b;
else a=c
end
end
I want all b in a list. How can I do this?
Upvotes: 0
Views: 1314
Reputation: 110
Given a loop which output variables a,b,c
, you can "append" these variables at the end of an array A
by adding at the end of the loop
A(end+1,:) = [a,b,c];
A(end+1,:)
created a new row to which [a,b,c]
are then assigned.
In your case you can create an empty list all_b=[]
before the while
loop.
Then you can add within the loop all_b(end+1) = b
, which will save the current b in an all_b list.
Upvotes: 1