% symbol at the start of a line

조회 수: 7 (최근 30일)
Isobel Munden
Isobel Munden 2020년 3월 10일
편집: Steven Lord 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]
  댓글 수: 1
Isobel Munden
Isobel Munden 2020년 3월 10일
Thank you very much!

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by