Iteration for loop cell array storage
조회 수: 2 (최근 30일)
이전 댓글 표시
I am doing a for loop that outputs a matrix "R" every iteration. I wanted to make a cell array to store each matrix however it only stores the final output i.e. overwrites the cell every iteration - any help?
ct=0;
for diamrod1 = 10e-9:5e-9:20e-9;
[r,t,R,T]=fv_trans_refl_2D_slabs(F, materials, d, pol);
ct=ct+1;
Rcollected{ct,1}=R;
end
after I run it the Rcollected cell only has a saved matrix at ct=3.
댓글 수: 0
답변 (1개)
Adam
2017년 6월 27일
This seems rather obvious, but it is often the obvious things that are hardest to see...
Nothing in your for loop depends on the diamrod1 loop variable. In particular this line:
[r,t,R,T]=fv_trans_refl_2D_slabs(F, materials, d, pol);
will evaluate to the same thing every time round the loop. This still would not explain why only ct=3 stores a matrix, but it would explain why all matrices stored would be the same.
댓글 수: 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!