% symbol at the start of a line

4 visualizaciones (últimos 30 días)
Isobel Munden
Isobel Munden el 10 de Mzo. de 2020
Editada: Steven Lord el 10 de Mzo. de 2020
Hello, What does the '%' symbol do when put at the start of a line in the programme? Thank you.

Respuestas (1)

John D'Errico
John D'Errico el 10 de Mzo. de 2020
Editada: Steven Lord el 10 de Mzo. de 2020
That turns the line into a comment. It is no longer used as code. A % can also appear later in the line.
When something is seen as a comment by MATLAB, the editor will display that part in green.
Finally, you can create a block comment, thus a block of lines that start with %{ and and with %} will now be seen as if they were all commented individually. (This capability was introduced into MATLAB some years ago, though I am not certain in which release that occurred.)
Some examples:
a = 5; % only the latter part of this line is a comment
% this next is just a comment, so not executable code
% a = 5;
%{
A block comment
aefgeqg
qethqt
qethq
%}
% a % symbol in quotes does not create a comment
% so anything that is part of a string is thus not a comment
sprintf('%0.5f',1/3)
ans =
'0.33333'
'% sefgetgqeqaghqthth'
[SL: typo fix]

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by