MATLAB Answers

0

Won't pass thru second else if condion Matlab

Asked by Mark Colonia on 6 Apr 2019
Latest activity Commented on by 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

I tried to edit madhan but, it will only send errors on the
"end"
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.
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.

Products

0 Answers