MATLAB: Can I comment a block of lines in an MATLAB file using /* … */ as I can in C

*{*//*blockccommentMATLABmultiline

I understand that in MATLAB we can comment line by line using % but this is troublesome, especially if I have a whole group of lines that I want to comment out temporarily. Is there anyway we can 'block' comment, like in 'C' where we can use /* at the beginning of a block of comments and */ at the the end of the block?

Best Answer

This enhancement has been made for Release 14 (R14). You can use the following syntax to comments a block of code in MATLAB release 14 (R14) onwards:
%{
...
Block of COMMENTS HERE
...
...
%}
%CODE GOES HERE
plot(1:10)
For previous product releases, please read below for any possible workarounds:
If you are using the MATLAB editor, you can highlight the block of code that you want to comment then select the "Text->Comment" menu item or type a Control-R to comment the whole block. To uncomment the block, once again select the block of code, select "Text->Uncomment" or type Control-T key combination. This functionality is also available through right-mouse-clicks.
You cannot comment your MATLAB code with /*....*/ as in C. However, the above workaround should allow you to accomplish the same goal, to comment an entire block.