Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
What am I not seeing here
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Here is a small script that I wrote after I missed a colon and saw some unexpected (by me) behavior in some work I was doing.
clc;
a=10;
for i=1length(a) % yes, it is i=<digit 1><no space><length(a)>
disp(i)
end
Yes, I know I am missing the colon in the for loop line, but that is exactly my point. I get this output at the command prompt,
ans =
1
1
but I am expecting an error
??? 1length(a)
|
Error: Unexpected MATLAB expression.
I know I am not able to see something, probably something silly, obvious and embarrassing, but I just don't know what. Would like somebody to help me out here, thanks in advance.
1 comentario
Jan
el 15 de Jun. de 2011
5 votes in 22 minutes - this is the current record here. You've written my "post of the week".
Respuestas (2)
Matt Fig
el 15 de Jun. de 2011
You are seeing the print out of length(a) then disp(i). I am thinking that this is a bug, or the parser is supposed to be so smart as to not let you error here. It certainly is unexpected!
I could see the parser recognizing a function call, but this works too:
a = 10;
for i = 7a
disp(i)
end
M-Lint underlines the a and says, "Use newline, semicolon or comma before this statement." So it is just a smart parser!
This works for more that FOR loops!
a = 10;
if 2a,end
and also,
while a==10a,end % ctrl+c ahead!
0 comentarios
Jan
el 15 de Jun. de 2011
Even in the command window of the ancient Matlab 6.5:
a = 10:12;
for i=2length(a), disp(8); end
>> ans =
3
8
>> disp(i)
i = 2
Strange. The parser seems to be lazy:
for i=2sin(1:4), end
>> ans = 0.8415 0.9093 0.1411 -0.7568
1 comentario
La pregunta está cerrada.
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!