Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comment out some part of a line in matlab function

As the question suggests I want to comment out some part of a line in MATLAB.

Also I want to comment out some part of a line not till the end of line.

Reason for this is, I have to try two different versions of a line and I don't want to replicate the line twice. I know it is easy to comment/uncomment if I replicate the line , But I want it this way.

like image 723
Nishant Avatar asked Jun 13 '14 12:06

Nishant


People also ask

How do you comment on a selected line?

Comments can be added to single lines of code (Ctrl + /) or blocks of code (Ctrl + Shift + /).

How do you comment out a chunk of code?

To comment out multiple code lines right-click and select Source > Add Block Comment. ( CTRL+SHIFT+/ ) To uncomment multiple code lines right-click and select Source > Remove Block Comment. ( CTRL+SHIFT+\ )

How do you highlight and comment in MATLAB?

Just type your comment and highlight the block, after which just do (CTRL + R) that is it. To uncomment a block of code just use (CTRL + T).

How do we add comments to a line of code?

The single line comment is //. Everything from the // to the end of the line is a comment. To mark an entire region as a comment, use /* to start the comment and */ to end the comment.


2 Answers

Within one line is not possible (afaik), but you can split up your term into multiple lines:

x=1+2+3 ... optional comments for each line
... * factorA ... can be inserted here
* factorB ...
+4;

Here * factorA is commented out and * factorB is used, resulting in the term x=1+2+3*factorB+4.

The documentation contains a similar example, commenting out one part of an array:

header = ['Last Name, ',      ...
          'First Name, ',     ...
      ... 'Middle Initial, ', ...
          'Title']
like image 143
5 revs Avatar answered Sep 20 '22 04:09

5 revs


Nope, this is not possible. From help '%':

%   Percent.  The percent symbol is used to begin comments.
    Logically, it serves as an end-of-line character. Any
    following text on the line is ignored or printed by the
    HELP system.

So just copy-paste the line, or write a tiny function so that it's easier to switch between versions.

like image 35
Rody Oldenhuis Avatar answered Sep 24 '22 04:09

Rody Oldenhuis