problem usibg if condition
Mostra commenti meno recenti
I have if ifelse else if the if condition is true thin code is doing it if its not true he will continue and check if the ifelse is true, but if its not true he check else in the else I want hem to return to if again
if (AirE==0)
if (S>=3&&S<=5)&&(M==10)
W=205;
E=3;
end
if (S>=3&&S<=5)&&(M==12.5)
W=200;
E=2.5;
end
if (S>=3&&S<=5)&&(M==20)
W=185;
E=2;
end
if (S>=3&&S<=5)&&(M==25)
W=180;
E=1.5;
end
if (S>=3&&S<=5)&&(M==40)
W=160;
E=1;
end
if (S>=3&&S<=5)&&(M==60)
W=155;
E=0.5;
end
if (S>=3&&S<=5)&&(M==70)
W=145;
E=0.3;
end
if (S>=8&&S<=10)&&(M==10)
W=225;
E=3;
end
if (S>=8&&S<=10)&&(M==12.5)
W=215;
E=2.5;
end
if (S>=8&&S<=10)&&(M==20)
W=200;
E=2;
end
if (S>=8&&S<=10)&&(M==25)
W=195;
E=1.5;
end
if (S>=8&&S<=10)&&(M==40)
W=175;
E=1;
end
if (S>=8&&S<=10)&&(M==60)
W=170;
E=0.5;
end
if (S>=8&&S<=10)&&(M==70)
W=160;
E=0.3;
end
if (S>=15&&S<=18)&&(M==10)
W=240;
E=3;
end
if (S>=15&&S<=18)&&(M==12.5)
W=230;
E=2.5;
end
if (S>=15&&S<=18)&&(M==20)
W=210;
E=2;
end
if (S>=15&&S<=18)&&(M==25)
W=205;
E=1.5;
end
if (S>=15&&S<=18)&&(M==40)
W=185;
E=1;
end
if (S>=15&&S<=18)&&(M==60)
W=180;
E=0.5;
end
if (S>=15&&S<=18)&&(M==70)
W=170;
E=0.3;
end
elseif(AirE==1)
if (S>=3&&S<=5)&&(M==10)
W=180;
E=8;
end
if (S>=3&&S<=5)&&(M==12.5)
W=175;
E=7;
end
if (S>=3&&S<=5)&&(M==20)
W=165;
E=6;
end
if (S>=3&&S<=5)&&(M==25)
W=160;
E=5;
end
if (S>=3&&S<=5)&&(M==40)
W=145;
E=4.5;
end
if (S>=3&&S<=5)&&(M==60)
W=145;
E=4;
end
if (S>=3&&S<=5)&&(M==70)
W=135;
E=3.5;
end
if (S>=8&&S<=10)&&(M==10)
W=200;
E=8;
end
if (S>=8&&S<=10)&&(M==12.5)
W=190;
E=7;
end
if (S>=8&&S<=10)&&(M==20)
W=180;
E=6;
end
if (S>=8&&S<=10)&&(M==25)
W=175;
E=5;
end
if (S>=8&&S<=10)&&(M==40)
W=160;
E=4.5;
end
if (S>=8&&S<=10)&&(M==60)
W=155;
E=4;
end
if (S>=8&&S<=10)&&(M==70)
W=150;
E=3.5;
end
if (S>=15&&S<=18)&&(M==10)
W=215;
E=8;
end
if (S>=15&&S<=18)&&(M==12.5)
W=205;
E=7;
end
if (S>=15&&S<=18)&&(M==20)
W=190;
E=6;
end
if (S>=15&&S<=18)&&(M==25)
W=185;
E=5;
end
if (S>=15&&S<=18)&&(M==40)
W=170;
E=4.5;
end
if (S>=15&&S<=18)&&(M==60)
W=165;
E=4;
end
if (S>=15&&S<=18)&&(M==70)
W=160;
E=3.5;
end
else
disp('not fro you')
end
if AirE==1
p1 = -6.667e-09;
p2 = 7.571e-06;
p3 = -0.004019;
p4 = 1.165;
wcr = p1*x^3 + p2*x^2 + p3*x + p4;
%R squre is 0.9996
end
if AirE==0
p1 = 1.818e-11;
p2 = -2.404e-08;
p3 = 1.329e-05;
p4 = -0.004792;
p5 = 1.291;
wcr = p1*x^4 + p2*x^3 + p3*x^2 + p4*x + p5;
%R squre is 0.9997
end
2 Commenti
Stephen23
il 26 Ott 2020
A much better use of MATLAB would be to put all of those boundary values into vectors and then do all of the comparisons at once using basic logical comparisons or histogram functions or interpolation or similar.
Priysha LNU
il 28 Ott 2020
Hi,
You may try to vectorize the code and then use a 'WHILE' loop to repeat the (if > elseif > else) conditions. You may add a break condition in the while loop as per your workflow to remove the possibility of the script being stuck in an infinite loop.
Hope this helps!
DISCLAIMER: These are my own views and in no way depict those of MathWorks.
Risposte (0)
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!