MATLAB Answers

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

4,542 ビュー (過去 30 日間)
Doug Hull
Doug Hull 2011 年 1 月 18 日
I want to do this in an easy way.

  3 件のコメント

Carol Hurwitz
Carol Hurwitz 2018 年 7 月 8 日
Hamid Nourani
Hamid Nourani 2020 年 4 月 21 日
Md.Al AMIN TALUKDER 2020 年 7 月 26 日
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

  2 件のコメント

James Tursa
James Tursa 2011 年 2 月 3 日
Also, the control-r and control-t work for C source code as well ... putting and removing the // style comments.
Kesam reddy Dhaneswara reddy
Kesam reddy Dhaneswara reddy 2020 年 8 月 20 日
Tq sir


その他の回答 (3 件)

CHUANQIANG ZHANG 2018 年 5 月 10 日
Ctrl + R comment selected lines. Ctrl + T uncomment select lines.

  0 件のコメント


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

  0 件のコメント


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
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.

  0 件のコメント





Community Treasure Hunt

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

Start Hunting!

Translated by