Illegal use of reserved keyword "end"

8 visualizaciones (últimos 30 días)
Aleksandra Pawlak
Aleksandra Pawlak el 27 de Dic. de 2020
Comentada: Aleksandra Pawlak el 27 de Dic. de 2020
Hi,
I have some problems with my code. I get 'Illegal use of reserved keyword "end"' command.
for z2=[0:0.01:max([a2,a3,a4,a5,a6,a7,a11,a13,a17,a19,a23,a25,a29,a31,a35,a37])]
if z2 > d2(length(a2))
e2=[1 1];
s2=[a2(length(a2)) max([a2,a3,a4,a5,a6,a7,a11,a13,a17,a19,a23,a25,a29,a31,a35,a37]);
plot(s2,100*e2,'color',[0.8500 0.3250 0.0980],'LineWidth',2)
end
end
Where as a result:
a2=[ 0 0.0090 0.0170 0.0260 0.0870 0.0960 0.1050 0.1130 0.1220 0.1310 0.1400 0.1570 0.1660 0.1740 0.1830 0.1920 0.2010 0.2090 0.2180 0.2270 0.2360 0.2440 0.2530 0.2620 0.2880 0.3050 0.3140 0.3230 0.3310]
d2=1
z2=[0:0.01:1.6310]

Respuesta aceptada

the cyclist
the cyclist el 27 de Dic. de 2020
In the statement
s2=[a2(length(a2)) max([a2,a3,a4,a5,a6,a7,a11,a13,a17,a19,a23,a25,a29,a31,a35,a37]);
you seem to have missed the closing square bracket to create the two-element vector s2. This leads to the very non-intuitive error message you got, because MATLAB hits that end statement in an unexpected way.

Más respuestas (1)

marie lasz
marie lasz el 27 de Dic. de 2020
you missed a closing of a square bracket.
s2=[a2(length(a2)) max([a2,a3,a4,a5,a6,a7,a11,a13,a17,a19,a23,a25,a29,a31,a35,a37]);
plot(s2,100*e2,'color',[0.8500 0.3250 0.0980],'LineWidth',2)]

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by