Sorry, the question is: why is my underfunction not remembering my earlier value of A1 and how can i make it to remember?
loop with easy underfunction
1 次查看(过去 30 天)
显示 更早的评论
function tretti
for k=1:3
F=results(k)
end
function h=results(k)
A ={k*2};
A1(k)= A
h=A1
%output: F=[] [] [6]
%what i want: F=[2] [4] [6] //cell array
回答(1 个)
Rik
2017-11-7
Because you are overwriting it every iteration.
function F=tretti
for k=1:3
F{k}=results(k);
end
function h=results(k)
A ={k*2};
A1(k)= A;
h=A1;
You should look into cellfun, it may be really useful for what you are trying to do.
2 个评论
Rik
2017-11-7
The modification of your code should work. You could also generate it as a vector or matrix, and then convert it to a cell with num2cell (or mat2cell).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!