% symbol at the start of a line
4 views (last 30 days)
Show older comments
Hello, What does the '%' symbol do when put at the start of a line in the programme? Thank you.
0 Comments
Answers (1)
John D'Errico
on 10 Mar 2020
Edited: Steven Lord
on 10 Mar 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]
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!