Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Multiline Comments

Subject: Multiline Comments

From: sdchapman@my-deja.com

Date: 10 Mar, 2000 20:04:02

Message: 1 of 7

Hi all,
   Is there any way to get multiline or block comments in Matlab?
The only comments I'm aware of are the single-line "%" type.

Thanks,
Steve Chapman
Arkansas Children's Hospital


Sent via Deja.com http://www.deja.com/
Before you buy.

Subject: Multiline Comments

From: Michael Robbins

Date: 10 Mar, 2000 20:45:22

Message: 2 of 7


> Is there any way to get multiline or block comments in Matlab?
> The only comments I'm aware of are the single-line "%" type.

There are three ways that I know of:

1. The best way is to use XEmacs instead of MEdit. There is a learning
curve, but it's well worth it. If you are using Emacs or XEmacs, merely
highlight your block, and type "<Control>-c" and then type ";"

2. Jordan Rosenthal wrote a function that works with MEdit (I attached
it at the bottom of this message.

3. You can use a macro in another editor

--
Michael Robbins, CFA
Director, Proprietary Trading
Debt Capital Markets, Canadian Imperial Bank of Commerce (World Markets)
michael.robbins@us.cibc.com



function commentize(pathname,b,e);
%function commentize(pathname,b,e);
%changes selected text to or from a block comment by inserting or
removing
'%'
% - to be called from the MEDIT tools menu

%Author: Iram J. Weinstein
% Science Applications International Corporation
 % weinsteini@saic.com

%Installation:
% Tools - Customize - Add
% Menu Text: &Block Comment
% Matlab Expression: commentize('$(Pathname)',$(BeginSel),$(EndSel))
% Set Option "Automatically reload externally modified files"

if computer ~='PCWIN'
   error('This function expects CRLF terminators to text lines. It will
need
work for UNIX or MAC environments.')
end

lf=char(10);
mark='%';

fp=fopen(pathname,'r+');
txt=fread(fp);
txt=char(txt');

%back up b and e to the beginning of their lines
while txt(b)~=lf, b=b-1;end
b=b+1;
while txt(b+1)==lf, b=b+2;end %skip blank lines

while txt(e)==lf,e=e-2;end
while txt(e)~=lf,e=e-1;end
e=e+1;

%decide whether to comment or uncomment
clines=0;lines=0;cloc=[];bloc=[];
k=b;
while k<=e,
   while txt(k+1)==lf, k=k+2; end
   lines=lines+1;
   if txt(k)==mark,
      clines=clines+1;
      cloc=[cloc k];
   else
      bloc=[bloc k];
   end
   while txt(k)~=lf,k=k+1;end
   k=k+1;
end

if lines==clines, %remove comment marks
   txt(cloc)=[];
else
   for k=length(bloc):-1:1,
      txt=[txt(1:bloc(k)-1) mark txt(bloc(k):end)];
   end
end

fseek(fp,0,-1);
fwrite(fp,txt');
fclose(fp);



Sent via Deja.com http://www.deja.com/
Before you buy.

Subject: Multiline Comments

From: Denis Gilbert

Date: 10 Mar, 2000 21:09:16

Message: 3 of 7

Steve, people in this forum have frequently proposed the following
solution:

if 0
    ..........
    multiple command lines you wish to disable
    .........
end

You can easily reenable that entire block of commands by replacing "if 0"
with "if 1".

I hope this helps! Denis Gilbert

sdchapman@my-deja.com wrote in article <8abkff$ute$1@nnrp1.deja.com>...
> Hi all,
> Is there any way to get multiline or block comments in Matlab?
> The only comments I'm aware of are the single-line "%" type.
>
> Thanks,
> Steve Chapman
> Arkansas Children's Hospital

Subject: Multiline Comments

From: Jordan Rosenthal

Date: 11 Mar, 2000 09:23:55

Message: 4 of 7

Michael,

> 2. Jordan Rosenthal wrote a function that works with MEdit (I attached
> it at the bottom of this message.

No, that wasn't my function and I certainly don't want to claim credit for
someone else's work. Unless it's really good. No, just kidding. :)

I had just reposted the function which was written by Iram J. Weinstein.
See the comments of the code.

Jordan


> function commentize(pathname,b,e);
> %function commentize(pathname,b,e);
> %changes selected text to or from a block comment by inserting or
> removing
> '%'
> % - to be called from the MEDIT tools menu
>
> %Author: Iram J. Weinstein
> % Science Applications International Corporation
> % weinsteini@saic.com

Subject: Multiline Comments

From: Gerard

Date: 2 May, 2013 14:39:08

Message: 5 of 7

sdchapman@my-deja.com wrote in message <8abkff$ute$1@nnrp1.deja.com>...
> Hi all,
> Is there any way to get multiline or block comments in Matlab?
> The only comments I'm aware of are the single-line "%" type.
>
> Thanks,
> Steve Chapman
> Arkansas Children's Hospital
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.

%{
....comments
}%

Subject: Multiline Comments

From: cece

Date: 8 Nov, 2013 19:09:06

Message: 6 of 7

"Gerard " <gweatherby@uchc.edu> wrote in message <klttqc$kif$1@newscl01ah.mathworks.com>...
> sdchapman@my-deja.com wrote in message <8abkff$ute$1@nnrp1.deja.com>...
> > Hi all,
> > Is there any way to get multiline or block comments in Matlab?
> > The only comments I'm aware of are the single-line "%" type.
> >
> > Thanks,
> > Steve Chapman
> > Arkansas Children's Hospital
> >
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
> %{
> ....comments
> }%

The last line should be:
%}

Thank you for heading me in the right direction, though :)

Subject: Multiline Comments

From: cece

Date: 8 Nov, 2013 19:10:15

Message: 7 of 7

"Gerard " <gweatherby@uchc.edu> wrote in message <klttqc$kif$1@newscl01ah.mathworks.com>...
> sdchapman@my-deja.com wrote in message <8abkff$ute$1@nnrp1.deja.com>...
> > Hi all,
> > Is there any way to get multiline or block comments in Matlab?
> > The only comments I'm aware of are the single-line "%" type.
> >
> > Thanks,
> > Steve Chapman
> > Arkansas Children's Hospital
> >
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
> %{
> ....comments
> }%

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us