Store each value generated in a for loop
조회 수: 2 (최근 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!