Won't pass thru second else if condion Matlab

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

What do you mean by won't read second else? Do you get an error? Does it simply not get inside the else block?
elseif no space between else and if
Yes TADA! it will only calculate the general case and won't update value of P5 as what I intend to do
I tried to edit madhan but, it will only send errors on the
"end"
Remove the superfluous end statements. You put them in because you had a separate if inside your else which needed its own end.
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)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Asked:

on 6 Apr 2019

Commented:

on 6 Apr 2019

Community Treasure Hunt

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

Start Hunting!