필터 지우기
필터 지우기

value of variable is changed in iteration

조회 수: 1 (최근 30일)
summyia qamar
summyia qamar 2016년 12월 15일
댓글: summyia qamar 2016년 12월 15일
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?
  댓글 수: 4
José-Luis
José-Luis 2016년 12월 15일
Please look at my answer that does what you want, in a simpler way.
Please accept the answer that best solves your problem.
summyia qamar
summyia qamar 2016년 12월 15일
but there's no option for answer acceptance here

댓글을 달려면 로그인하십시오.

채택된 답변

José-Luis
José-Luis 2016년 12월 15일
편집: José-Luis 2016년 12월 15일
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(:)];
  댓글 수: 1
summyia qamar
summyia qamar 2016년 12월 15일
oh thanks alot.its done..I want to represent the vales 2, 2.5,2.8,3 as W1,W2,W3,W4 in the final matrix..how is it possible. I tried (==)method but its not working

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Adam
Adam 2016년 12월 15일
Why would you ever choose to do this in 7 nested for loops?!
You could do this far quicker just using the original a, b, c etc rather than z, y, x in a loop.
What is the final result you are trying to achieve?
As far as your bug goes though you are reassigning f in your loop which is also used as one of your original variables. Rename this and it will probably do what you want.
  댓글 수: 1
summyia qamar
summyia qamar 2016년 12월 15일
actually I'm just a beginner in matlab that's why doing in basic steps

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by