MATLAB Answers

How do I comment out a large block of code in MATLAB?

조회 수: 7,230(최근 30일)
Doug Hull
Doug Hull 2011년 1월 18일
댓글: Shapol Mohamed 2021년 3월 18일
I want to do this in an easy way.
  댓글 수: 3
Md.Al AMIN TALUKDER
Md.Al AMIN TALUKDER 2020년 7월 26일
ctrl+r
u can use both for single or multiple line.

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

채택된 답변

Doug Hull
Doug Hull 2011년 1월 18일
편집: MathWorks Support Team 2018년 11월 8일
To comment out a large block of code in the Editor or Live Editor, select the code and on the "Editor" or "Live Editor" tab, click the "Comment" button. This inserts a "%" symbol in front of each selected line. Alternatively, select the code and type "Ctrl" + "R". To uncomment the selected text, click the "Uncomment" button or type "Ctrl" + "T".
You also can use the block comment operators "%{" and "%}". The "%{" and "%}" operators must appear alone on the lines that immediately precede and follow the block of help text. For example:
%{
Stuff to be commented out
%}
  댓글 수: 5
Shapol Mohamed
Shapol Mohamed 2021년 3월 18일
In Matlab 2020, you have to use ctrl+/ (cmd+/ for mac) to comment a block and to uncomment you have to use ctrl+t (cmd+t for mac).

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

추가 답변(3개)

CHUANQIANG ZHANG
CHUANQIANG ZHANG 2018년 5월 10일
Ctrl + R comment selected lines. Ctrl + T uncomment select lines.
https://stackoverflow.com/questions/30925796/is-there-a-shortcut-key-to-comment-multiple-lines-in-matlab-editor/30926004#30926004

Wesam Rezk
Wesam Rezk 2018년 3월 30일
Simply start with *... and write whatever you want. This will enable you to write a very long comment line
For example *... This is a very very long comment

Wick
Wick 2018년 5월 1일
편집: Wick 2018년 5월 1일
Rather than comment large sections of code, I bypass them with the following syntax.
for dont_go_here = []
% code I want to skip including all nested comments, etc. can stay here unmolested
end
This assumes that your if, for, case, try, and switch commands within that block are all terminated properly with an 'end' Otherwise the script won't parse.

제품


릴리스

R2010b

Community Treasure Hunt

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

Start Hunting!

Translated by