Iteration for loop cell array storage

1 次查看(过去 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.

回答(1 个)

Adam
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.

类别

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