Why do I get the error "illegal use of reserved keybord "while""?

4 Ansichten (letzte 30 Tage)
andres
andres am 28 Mär. 2014
Beantwortet: andres am 28 Mär. 2014
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
  1 Kommentar
Image Analyst
Image Analyst am 28 Mär. 2014
You forgot to paste the error message. "keybord" is not even an English word, and it's not in your code either so I know that's not the real error message. Please paste in ALL the red text, including line numbers, lines of code, everything . Don't snip or paraphrase like you did.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Michael
Michael am 28 Mär. 2014
Both times you use "costoviaF" (lines 24 and 17) you fail to close the bracket at the end of your line.

Weitere Antworten (1)

andres
andres am 28 Mär. 2014
Wow, it was a very simple mistake, thank you very much, now it is working!

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by