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 Kommentar

Jan
Jan am 1 Jun. 2018
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 1 Jun. 2018

0 Stimmen

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.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 1 Jun. 2018

Beantwortet:

Jan
am 1 Jun. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by