MATLAB: Do I get the error “illegal use of reserved keybord “while””

enderrorillegal usewhile

I need to run the following code, where the function @opt is already defined. When I try to run it, I get the error "illegal use of reserved keybord "while"". Actually, the "end" that is not well located is not recognized by matlab as an end (it appears written in black instead of blue). Why does this happen and how can I fix it? Thanks a lot in advance.
if true
% E3=zeros(50,50,4);
rn=sqrt(2*(1-cos(2*pi/n)));
for k=1:50
k
for j=1:51-k
alfa=k/52;
beta=j/52;
gamma=1-alfa-beta;
alfagorro=alfa/(1-beta);
gammagorro=gamma/(1-beta);
H=1;
Hgorro=H;
F=(n-1-H)/2;
[f,c]=fmincon(@opt,[1 1 1],[],[],[],[],[0 0 0],[],[],options);
costoviaH=pe/(2*f(2))+pv*[2*T0+t*(a*alfa*Y/(H*n*f(2))+b*alfagorro*Y/(H*n*f(2))+a*gamma*Y/(2*n*(n-1)*f(2))+b*gammagorro*Y/(2*n*(n-1)*f(2)))];
costoviaF=pe/(2*f(2))+pv*[F*rn*T0+(2*(F-1)+1/2)*t*(a*gamma*F*Y/(n*(n-1)*f(3))+b*gammagorro*F*Y/(n*(n-1)*f(3)));
while costoviaH<costoviaF && H<n-1
H=H+2;
Hgorro=H;
[f,c]=fmincon(@opt,[1 1 1],[],[],[],[],[0 0 0],[],[],options);
costoviaH=pe/(2*f(2))+pv*[2*T0+t*(a*alfa*Y/(H*n*f(2))+b*alfagorro*Y/(H*n*f(2))+a*gamma*Y/(2*n*(n-1)*f(2))+b*gammagorro*Y/(2*n*(n-1)*f(2)))];
F=(n-1-H)/2;
costoviaF=pe/(2*f(2))+pv*[F*rn*T0+(2*(F-1)+1/2)*t*(a*gamma*F*Y/(n*(n-1)*f(3))+b*gammagorro*F*Y/(n*(n-1)*f(3)));
end
for L=1:3
E3(k,j,L)=f(L);
end
E3(k,j,4)=c;
end
end
end

Best Answer

Both times you use "costoviaF" (lines 24 and 17) you fail to close the bracket at the end of your line.
Related Question