MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Doug Hull
on 18 Jan 2011

I want to do this in an easy way.

Answer by Doug Hull
on 18 Jan 2011

Accepted answer

Starting in MATLAB 7 (R14), the syntax is:

%{ Stuff to be commented out %}

You can also highlight a section of code and type control-r to comment out the code -- this will place a percent symbol (%) at the beginning of the line. Typing control-t will uncomment the lines by removing any percent symbol that is the first non-blank character on the line.

If you have an older version, the built-in editor in MATLAB 6.0 has a block-comment feature, which will simply put a comment character on each line. Or you can use matlab-mode for Emacs, which supports this as well.

If you are using an even older version, use this:

if 0 commented out code end

This is not the best solution, since parse errors inside that block will cause an error.

[From the MATLAB FAQ of Ancient Times]

James Tursa
on 3 Feb 2011

Also, the control-r and control-t work for C source code as well ... putting and removing the // style comments.

## 0 Comments