Running a while loop for an array
古いコメントを表示
I am trying to run the following length of code through a while loop for different t values checking for the t value which meets both the outlined conditions of the while loop. Any advice on getting it to work?
if true
% code
end
unity = 2;
t = 0.001:0.001:1;
while i < length(t+1)
while (unity(i) > 1) && (unity2 > 1)
Area = pi.*(D.^2-(D-2.*t).^2)./4;
P=G./Area;
[Fa,Fe] = Buckling(D,L,Fy,t,E,k);
[Fb] = Bending(D,Fy,t,E);
unity = P./Fa+(Cm.*sqrt(MIP.^2+MOP.^2))./((1-(P./Fe)).*Fb);
unity2 = P./(0.6.*Fy)+(sqrt(MIP.^2+MOP.^2))./Fb;
end
i = i+1;
end
1 件のコメント
Jan
2018 年 6 月 1 日
Hard to answer, because it is not clear what the code should do. If all we see is the failing code, we cannot invent its purpose to fix it.
There are 2 while loops. It is not clear, where you try to check the values of t.
回答 (1 件)
Jan
2018 年 6 月 1 日
while i < length(t+1)
I guess you mean:
while i < length(t) + 1
This fails, because i is undefined before the loop. Use a for loop instead.
while (unity(i) > 1) && (unity2 > 1)
This fails for undefined variables unity and unity2 also. Define them at first. Is unity a vector or scalar? It is not clear, why you write unity(i) at this line.
Try to fix these points and post the improved code again. Then add clear explanations of the purpose. Otherwise fixing mean guessing.
カテゴリ
ヘルプ センター および 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!