Storing for loop nested value in a vector
12 次查看(过去 30 天)
显示 更早的评论
Hi, I have the following nested for loop:
for i=0:3
for ii=0:3
for iii=0:3
f = (i/2) + (ii/3) + (iii/4);
end
end
end
I would like to save all the output f in a vector that would store all the output. How can I do that? Thanks!
0 个评论
采纳的回答
Walter Roberson
2017-11-12
编辑:Walter Roberson
2017-11-12
f = zeros(4,4,4);
for i=0:3
for ii=0:3
for iii=0:3
f(iii+1,ii+1,i+1) = (i/2) + (ii/3) + (iii/4);
end
end
end
f = f(:);
2 个评论
alice
2020-3-26
I am also working with nested loops and have a similar code structure. Wondering how to get a table of the indices i,ii,iii and f.
更多回答(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!