Storing values for each iteration of a for loop

9 views (last 30 days)
Hello,
How do I store values from each iteration of the for loop to make one vector with all the outputs of each iteration?
In my code, I want to store the value of x (size of matrix trial) for each iteration of the for loop. Thanks
a=0;%
b=10;
Trial=[ ];
Iterations=zeros(1,b);
for k = 1 :b
while a ~= 7
Int = randi([1 12],1,1);
a=num2str(Int);
a=str2double(a);
Trial=[Trial;a];
end
[x,y]= size(Trial);
Iterations(1,k)=x;
end

Accepted Answer

Ryan Callaghan
Ryan Callaghan on 26 Sep 2020
I just figured out my problem. I needed to reinitialize the variables of both trial[] and a=0 inside of the for loop.

More Answers (0)

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!