MATLAB: Value of variable is changed in iteration

loop iterationMATLAB

a=[2 2.8];b=[2.8 3];c=[2.5 3];d=[2 2.8];e=[2.5 3];f=[2.8,3];g=[2.5 3];
m=[];
for z=a;
for y=b;
for x=c;
for w=d;
for v=e;
for u=f;
for t=g;
f=48*z+33*y+10*x+37*w+30*v+45*u+64*t;
m=[m;z y x w v u t f]
end
end
end
end
end
end
end
the 5th iteration shown is result is
m =
2 2.8 2.5 2 2.5 2.8 2.5 648.4
2 2.8 2.5 2 2.5 2.8 3 680.4
2 2.8 2.5 2 2.5 3 2.5 657.4
2 2.8 2.5 2 2.5 3 3 689.4
2 2.8 2.5 2 3 689.4 2.5 31560
and so on the values of 6th colume are changed while I have given the values f=[2.8 3]..why it is selecting 689.4 in next iteration?

Best Answer

Is this what you are trying to do?
a=[2 2.8];
b=[2.8 3];
c=[2.5 3];
d=[2 2.8];
e=[2.5 3];
f=[2.8,3];
g=[2.5 3];
[A,B,C,D,E,F,G] = ndgrid(a,b,c,d,e,f,g);
result = [A(:),B(:),C(:),D(:),E(:),F(:),G(:)];
temp_var = (48 .* A) + (33 .* B) + (10 .* C) + (37 .* D) + (30 .* E) + (45 .*F) + (64 .* G);
result = [result, temp_var(:)];