Nishant
Nishant

Reputation: 2619

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.

Upvotes: 13

Views: 6760

Answers (2)

Daniel
Daniel

Reputation: 36710

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']

Upvotes: 27

Rody Oldenhuis
Rody Oldenhuis

Reputation: 38032

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.

Upvotes: 2

Related Questions