How do I comment out a large block of code in MATLAB?
4,211 views (last 30 days)
Show older comments
Doug Hull
on 18 Jan 2011
Commented: THONTI BEERAIAH
on 18 Jan 2023 at 7:13
I want to do this in an easy way.
3 Comments
Accepted Answer
Doug Hull
on 18 Jan 2011
Edited: MathWorks Support Team
on 8 Nov 2018
5 Comments
Shapol Mohamed
on 18 Mar 2021
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).
More Answers (3)
CHUANQIANG ZHANG
on 10 May 2018
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
0 Comments
Wesam Rezk
on 30 Mar 2018
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 Comments
Wick
on 1 May 2018
Edited: Wick
on 1 May 2018
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.
1 Comment
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!