jdl
jdl

Reputation: 6323

How can I do group commenting without commenting each line in MATLAB?

How can I comment a group of lines without commenting each line?

I.e., like in C:

/*
printf("hello");
printf("there");
*/

In MATLAB, the only way I know to do this is to comment each line:

%disp('hello')
%disp('there')

I have a 100 lines to comment out, and I would prefer to group comment it like in C.

Upvotes: 13

Views: 14842

Answers (5)

Fthi.a.Abadi
Fthi.a.Abadi

Reputation: 322

You can use keyboard shortcuts:

To comment multiple lines: Ctrl + R

To uncomment multiple lines: Ctrl + T

It works perfect in MATLAB 2016.

Upvotes: 0

pegah
pegah

Reputation: 1

Select all lines and then do:

For commenting:

From the Text menu → Comment

For uncommenting:

From the Text menu → Uncomment

Upvotes: 0

zeal
zeal

Reputation: 485

Or just select the group of lines you want to comment, and then use keystroke Ctrl + / (forward slash)'.

And voila, it will comment each line in the selected block with % as one would do individually.

To undo, I tried, but I don't know what key stroke can work.

Upvotes: 0

im so confused
im so confused

Reputation: 2111

  1. MATLAB v7+:

     %{
     ...code to be commented
     %}
    
  2. Use the editor:

    Select all the lines, and then choose toggle comment or something in the menu. It's there.

Upvotes: 6

Franck Dernoncourt
Franck Dernoncourt

Reputation: 83157

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

%{
...
Block of COMMENTS HERE
...
...
%}
%CODE GOES HERE
plot(1:10)

Upvotes: 16

Related Questions