Storing values for each iteration of a for loop

1 次查看(过去 30 天)
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

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by