I just figured out my problem. I needed to reinitialize the variables of both trial[] and a=0 inside of the for loop.
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
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!