Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Error: File: testem.m Line: 87 Column: 5 Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Kindly help me in rectifing it
0 comentarios
Respuestas (1)
Steven Lord
el 17 de Nov. de 2020
Editada: Steven Lord
el 17 de Nov. de 2020
If you're going to put the end keyword (or the elseif keyword that's part of an if statement) on the same line as another statement, separate them with either comma or semicolon.
for k = 1:10, if k == 5, disp('Hello'), elseif k == 7, disp('Goodbye'), end, end % works
% What follows is the output of the commands above
Hello
Goodbye
Compare this with the version without commas.
for k = 1:10 if k == 5 disp('Hello') elseif k == 7 disp('Goodbye') end end % will not work
% What follows is the text of the error when I tried running the previous line
for k = 1:10 if k == 5 disp('Hello') elseif k == 7 disp('Goodbye') end end % will not work
↑
Error: Illegal use of reserved keyword "elseif".
My personal preference is not to write multiple statements on one line like this. The following does take up more vertical real estate on screen, but it also (IMO) makes it easier to understand what end goes with what other keyword.
for k = 1:10
if k == 5
disp('Hello')
elseif k == 7
disp('Goodbye')
end
end
0 comentarios
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!