Store each value generated in a for loop
6 次查看(过去 30 天)
显示 更早的评论
I have a bit of code which generates a value P and updates it every iteration. How can i store each of these values generated and then plot them on a graph?
0 个评论
回答(1 个)
David Hill
2022-3-9
for k=1:100
p(k)=%your update for p
end
plot(p);
2 个评论
David Hill
2022-3-11
Use a cell array. Your sizes each iteration might be different based on the number of nonzeros.
P=cell(1000,1);
for n = 1:1000
P{n} = nonzeros(Q_new.*C);
end
另请参阅
类别
在 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!