How do I comment out a large block of code in MATLAB?
6,576 ビュー (過去 30 日間)
古いコメントを表示
I want to do this in an easy way.
3 件のコメント
採用された回答
Doug Hull
2023 年 8 月 29 日
編集済み: MathWorks Support Team
2023 年 8 月 29 日
5 件のコメント
Steven Lord
2021 年 3 月 12 日
That functionality is still present in releases R2020a, R2020b, and R2021a. It is possible that something about your file or how you're writing these comment delimiters is preventing them from being interpreted as block comments. For instance, %{ and %} must appear alone on a line.
x = 1
%{ start of block comment?
y = 2
%}
z = 3
%{
w = 4
v = 5
%}
Because of the text following the %{ before "y = 2" it is a regular comment, not a block comment. So we execute the line that creates the y variable.
Because there is no %{ associated with the %} before "z = 3" it too is a regular comment and the z variable is created.
The %{ and %} surrounding the lines defining the w and v do comprise a block comment, so those variables are not created.
whos
Can you show us a small code segment where you see %{ and %} not functioning as block comments?
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
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
3 件のコメント
Steven Lord
2023 年 6 月 15 日
Search the list of keyboard shortcuts for the word "comment" or for the key combination Ctrl+T and you should see the actions associated with commenting out code or that will be performed in various components of the MATLAB Desktop in the keyboard shortcut set you've told MATLAB to use.
In my MATLAB installation using the Windows keyboard shortcut set, Ctrl+T creates a new tab in the Help Browser but uncomments code when used in the Editor.
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
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.
参考
カテゴリ
Help Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!