% symbol at the start of a line

4 次查看(过去 30 天)
Isobel Munden
Isobel Munden 2020-3-10
Hello, What does the '%' symbol do when put at the start of a line in the programme? Thank you.

回答(1 个)

John D'Errico
John D'Errico 2020-3-10
编辑:Steven Lord 2020-3-10
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]

标签

Community Treasure Hunt

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

Start Hunting!

Translated by