why does this line of code give error- disp("The density of " + element ... + "is" + density). When i press the 'enter ' key after the 3 dots and rerun, it works.
Mostrar comentarios más antiguos
if doPlot == 1
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
else
disp("The Density of " + element ... + "is" + density)
end
Respuesta aceptada
Más respuestas (1)
John D'Errico
el 18 de Ag. de 2024
Editada: John D'Errico
el 18 de Ag. de 2024
Do this instead:
disp("The Density of " + element + " is " + density)
What did you write?
disp("The Density of " + element ... + "is" + density)
This must fail, because you stuffed that ... line continuation flag in there. But you did not actually split the line of code onto a second line. That confuses MATLAB. Do you see the second half of the line is green? That tells you MATLAB apparently thinks that second part of the line after the ellipsis is a comment. And now it thinks the line is incomplete, that a closing parens is missing, etc. Remember: anything in green was interpreted as a comment.
If you wanted to put the ellipsis inside quotes, to be displayed, that would work. But computers are very easily confused.
1 comentario
funmilayo
el 18 de Ag. de 2024
Categorías
Más información sobre File Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!