MATLAB: Storing for loop nested value in a vector

for loopgrowing vector;nested loop

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!

Best Answer

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(:);