How to save data from for loop into cell without rewriting?
1 次查看(过去 30 天)
显示 更早的评论
Dear all,
I have this code:
A ={5,2};
c = cell(size(A))
v = 0:0.1:1
idx = 1;
for j = 0:0.5:1
v(idx) = j;
['x-' num2str(j) '.^2+ (y- 0.5) .^2<0.1^2, ''x,' 'y,' 'z'];
select_fcn = inline('(x-j).^2+(y-0.5).^2<0.1^2','x','y','z');
img_2.elem_data = 1 + elem_select(img_2.fwd_model, select_fcn);
idx = idx + 1;
figure
show_fem(img_2);
vh = fwd_solve(img_1);
vi = fwd_solve(img_2);
img_3 = inv_solve (imdl,vh,vi);
figure
show_fem(img_3);
c{k,1}=j;
c{k,2} = idx
end
I would like to save data (j and idx) to cell, but without rewriting. Like in my case in Comand Window:
c =
[] []
[] []
[] []
[] []
[4] [0.5000]
c =
[] []
[] []
[] []
[] []
[4] [1]
Why didn´t fill whole cell array? Why was filled only one line and still be rewritten?
I have no idea.
Thank you for any ideas.
3 个评论
Stephen23
2015-1-28
Note that you should not use i of j as your loop variables, as these are the names of the inbuilt imaginary unit .
采纳的回答
Star Strider
2015-1-23
You increment ‘idx’ by 1 in each iteration, so I would add one line here to define ‘k’:
k = idx;
c{k,1}=j;
c{k,2} = idx;
That should solve your problem.
4 个评论
Star Strider
2015-1-28
I honestly have no idea. It would be best for you to post this as a new Question. Attach the file for the code that is producing the figure, so we can experiment with it.
更多回答(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!