MATLAB Answers

Won't pass thru second else if condion Matlab

12 views (last 30 days)
Mark Colonia
Mark Colonia on 6 Apr 2019
Commented: Image Analyst on 6 Apr 2019
Why won't it read the second else if I try to run? Help me please! I attached a file
if (delta_p~=0) %General Case%
summation=((input_data(1,3)+(loss_data(1,1)*input_data(1,2)))/(2*(input_data(1,3)+(lambda*loss_data(1,1)))^2))+((input_data(2,3)+(loss_data(2,2)*input_data(2,2)))/(2*(input_data(2,3)+(lambda*loss_data(2,2)))^2))+((input_data(3,3)+(loss_data(3,3)*input_data(3,2)))/(2*(input_data(3,3)+(lambda*loss_data(3,3)))^2))+((input_data(4,3)+(loss_data(4,4)*input_data(4,2)))/(2*(input_data(4,3)+(lambda*loss_data(4,4)))^2))+((input_data(5,3)+(loss_data(5,5)*input_data(5,2)))/(2*(input_data(5,3)+(lambda*loss_data(5,5)))^2));
fprintf('\tSummation: %5.10f\n', summation);
else if (delta_p==0)&& (p5>mwlimits(5,2)) %Start of P5 random
p5=mwlimits(5,2);
fprintf('\tP5 new: %5.4f', p5);
delta_p=pd+ploss-p1-p2-p3-p4-p5;
summation=((input_data(1,3)+(loss_data(1,1)*input_data(1,2)))/(2*(input_data(1,3)+(lambda*loss_data(1,1)))^2))+((input_data(2,3)+(loss_data(2,2)*input_data(2,2)))/(2*(input_data(2,3)+(lambda*loss_data(2,2)))^2))+((input_data(3,3)+(loss_data(3,3)*input_data(3,2)))/(2*(input_data(3,3)+(lambda*loss_data(3,3)))^2))+((input_data(4,3)+(loss_data(4,4)*input_data(4,2)))/(2*(input_data(4,3)+(lambda*loss_data(4,4)))^2));
fprintf('\tSummation: %5.10f\n', summation);
else if (delta_p==0)&& (p5<mwlimits(5,1))
p5=mwlimits(5,1);
fprintf('\tP5 new: %5.4f', p5);
delta_p=pd+ploss-p1-p2-p3-p4-p5;
summation=((input_data(1,3)+(loss_data(1,1)*input_data(1,2)))/(2*(input_data(1,3)+(lambda*loss_data(1,1)))^2))+((input_data(2,3)+(loss_data(2,2)*input_data(2,2)))/(2*(input_data(2,3)+(lambda*loss_data(2,2)))^2))+((input_data(3,3)+(loss_data(3,3)*input_data(3,2)))/(2*(input_data(3,3)+(lambda*loss_data(3,3)))^2))+((input_data(4,3)+(loss_data(4,4)*input_data(4,2)))/(2*(input_data(4,3)+(lambda*loss_data(4,4)))^2));
fprintf('\tSummation: %5.10f\n', summation);
else if(delta_p==0)&&((p5>mwlimits(5,1))&&(p2<mwlimits(5,2)))
p5=p5;
fprintf('\tP5 new: %5.4f', p5);
delta_p=pd+ploss-p1-p2-p3-p4-p5;
summation=((input_data(1,3)+(loss_data(1,1)*input_data(1,2)))/(2*(input_data(1,3)+(lambda*loss_data(1,1)))^2))+((input_data(2,3)+(loss_data(2,2)*input_data(2,2)))/(2*(input_data(2,3)+(lambda*loss_data(2,2)))^2))+((input_data(3,3)+(loss_data(3,3)*input_data(3,2)))/(2*(input_data(3,3)+(lambda*loss_data(3,3)))^2))+((input_data(4,3)+(loss_data(4,4)*input_data(4,2)))/(2*(input_data(4,3)+(lambda*loss_data(4,4)))^2))+((input_data(5,3)+(loss_data(5,5)*input_data(5,2)))/(2*(input_data(5,3)+(lambda*loss_data(5,5)))^2));
fprintf('\tSummation: %5.10f\n', summation);
end
end
end %End of p5 random

  6 Comments

Show 3 older comments
Mark Colonia
Mark Colonia on 6 Apr 2019
I tried to edit madhan but, it will only send errors on the
"end"
Rik
Rik on 6 Apr 2019
Remove the superfluous end statements. You put them in because you had a separate if inside your else which needed its own end.
Image Analyst
Image Analyst on 6 Apr 2019
Too hard to read. Try this. Type control-a (to select all), control-i (to properly indent your code). then paste back here. Then highlight your pasted code and click the Code icon to format it as code.
Also, you put a space between else and if
else if ............
which I believe is equivalent to
else
if ............
So, do you want that or do you really want elseif (all one word)
elseif ..........................

Sign in to comment.

Answers (0)

Sign in to answer this question.

Products