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
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
Jan 2018년 6월 1일

0 개 추천

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에 대해 자세히 알아보기

질문:

2018년 6월 1일

답변:

Jan
2018년 6월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by