while loops not work using randsample
이전 댓글 표시
please why this code is not work,array u and w has no values.
wi=10000000;
bwf=1668839.63;
bwm=352103.035;
p=1;
T = [];u=[];w=[];nf2ar=[];nm2ar=[];nf3ar=[];nm3ar=[];
for k=1:5
A= [1 2 3 4 5 6 7];
b = [1 2 3 4 5 6 7];
nf2 = randsample(A,1);
nf2ar=[nf2ar,nf2];
nm2 = randsample (b,1);
nm2ar=[nm2ar,nm2];
eq1=((bwf*nf2)/wi)+((bwm*nm2)/wi);
nf3 = randsample(A,1);
nf3ar=[nf3ar,nf3];
nm3 = randsample (b,1);
nm3ar=[nm3ar,nm3];
eq2=((bwf*nf3)/wi)+((bwm*nm3)/wi);
while (eq1<1 && eq2>1)
eq11=((bwf*nf2)/wi)+((bwm*(nm2+p))/wi);
eq22=((bwf*nf3)/wi)+((bwm*(nm3-p))/wi);
while (eq1>1 && eq2<1)
eq11=((bwf*nf2)/wi)+((bwm*(nm2-p))/wi);
eq22=((bwf*nf3)/wi)+((bwm*(nm3+p))/wi);
u= [u,eq11];
w=[w,eq22];
g=sum(u);
x= g/5;
G=sum(w);
y=G/5;
end
end
end
채택된 답변
추가 답변 (1개)
Guillaume
2019년 11월 7일
Maybe if you used proper indenting in your code, you'd see the silliness of it:
%... code irrelevant
while eq1 < 1 && eq2 > 1
%so if we get here we know that eq1 IS SMALLER than 1 AND eq2 IS GREATER than 1
%... stuff that doesn't change eq1 or eq2
while eq > 1 && eq2 < 1 %we know it's NEVER the case otherwise we wouldn't get here
%u and w calculated here
%guaranteed to never happen!
end
end
카테고리
도움말 센터 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!