Thread Subject: Code folding

Subject: Code folding

From: juliette Salexa

Date: 28 May, 2009 20:41:01

Message: 1 of 15

I have a bunch of lines of code that I just want to hide. They are not part of a function, or comment, or anything like that, so when I highlight the text and click on text->code folding , it doesn't let me chose any of the options.

Is it possible to hide arbitrary lines of code in the M-file editor ??

I would be very shocked if not.

Subject: Code folding

From: Alan B

Date: 28 May, 2009 20:48:01

Message: 2 of 15

"juliette Salexa" <n_dattani@hotmail.com> wrote in message <gvmsst$m5i$1@fred.mathworks.com>...
> I have a bunch of lines of code that I just want to hide. They are not part of a function, or comment, or anything like that, so when I highlight the text and click on text->code folding , it doesn't let me chose any of the options.
>
> Is it possible to hide arbitrary lines of code in the M-file editor ??
>
> I would be very shocked if not.

You should be able to define cells using '%%' at the beginning of a line, and fold any of those.

Subject: Code folding

From: juliette Salexa

Date: 28 May, 2009 20:56:02

Message: 3 of 15

"Alan B" <monguin61@yahoo.com> wrote in message <gvmta1$j29$1@fred.mathworks.com>...
> "juliette Salexa" <n_dattani@hotmail.com> wrote in message <gvmsst$m5i$1@fred.mathworks.com>...
> > I have a bunch of lines of code that I just want to hide. They are not part of a function, or comment, or anything like that, so when I highlight the text and click on text->code folding , it doesn't let me chose any of the options.
> >
> > Is it possible to hide arbitrary lines of code in the M-file editor ??
> >
> > I would be very shocked if not.
>
> You should be able to define cells using '%%' at the beginning of a line, and fold any of those.

I have my code divided into many cells, but how do I collapse a cell so that it's not visible ?? I've tried highlighting it and going "text->code folding" but none of the options are available for selection.

Subject: Code folding

From: Alan B

Date: 28 May, 2009 21:03:02

Message: 4 of 15

"juliette Salexa" <n_dattani@hotmail.com> wrote in message <gvmtp2$juk$1@fred.mathworks.com>...
> "Alan B" <monguin61@yahoo.com> wrote in message <gvmta1$j29$1@fred.mathworks.com>...
> > "juliette Salexa" <n_dattani@hotmail.com> wrote in message <gvmsst$m5i$1@fred.mathworks.com>...
> > > I have a bunch of lines of code that I just want to hide. They are not part of a function, or comment, or anything like that, so when I highlight the text and click on text->code folding , it doesn't let me chose any of the options.
> > >
> > > Is it possible to hide arbitrary lines of code in the M-file editor ??
> > >
> > > I would be very shocked if not.
> >
> > You should be able to define cells using '%%' at the beginning of a line, and fold any of those.
>
> I have my code divided into many cells, but how do I collapse a cell so that it's not visible ?? I've tried highlighting it and going "text->code folding" but none of the options are available for selection.

Is there an option in preferences to allow code folding for different types of code blocks, including cells? I'm currently using an older version of Matlab that does not support folding, but I'm fairly sure that in the past, I've used code folding with cells.

Subject: Code folding

From: someone

Date: 28 May, 2009 21:09:02

Message: 5 of 15

"Alan B" <monguin61@yahoo.com> wrote in message <gvmta1$j29$1@fred.mathworks.com>...
> "juliette Salexa" <n_dattani@hotmail.com> wrote in message <gvmsst$m5i$1@fred.mathworks.com>...
> > I have a bunch of lines of code that I just want to hide. They are not part of a function, or comment, or anything like that, so when I highlight the text and click on text->code folding , it doesn't let me chose any of the options.
> >
> > Is it possible to hide arbitrary lines of code in the M-file editor ??
> >
> > I would be very shocked if not.
>
> You should be able to define cells using '%%' at the beginning of a line, and fold any of those.

Other methods include block comments:

To comment a contiguous group of lines, type %{ before the first line and %} after the last line you want to comment. This is referred to as a block comment. The lines that contain %{ and %} cannot contain any other text. After typing the opening block comment symbol, %{, all subsequent lines assume the syntax highlighting color for comments until you type the closing block comment symbol, %}. Remove the block comment symbols, %{ and %}, to uncomment the lines.

Or, in the MATLAB Editor select Text -> Comment (or Ctrl+R) and Text -> Uncomment ( or Ctrl+T) to comment or uncomment the selected lines.

An "old-school" method is to surround the lines with an if block like:
debug = 0;
if debug
  lines to be ignored...
end
then when you want to use them change to:
debug = 1;
if debug
  execte these lines...
end

(debug can be an optional input to you function as well)

Subject: Code folding

From: Juliette Salexa

Date: 29 May, 2009 16:07:02

Message: 6 of 15

When I go to preferences -> code folding, the only programming constructs that I can hide are "funciton code" and "function help"

Also, I don't want my hidden code to be commented. By no means at all. The code is supposed to still be part of the running program, just not visible all the time as it takes up a lot of space and makes it hard to read. And I don't want to make it part of a function.

Subject: Code folding

From: Juliette Salexa

Date: 2 Jun, 2009 19:59:02

Message: 7 of 15

Okay, it's been quite some time now and I still haven't found a way to fold my code. In fact, I can't even fold cells. I'd be extremely surprised if MATLAB doesn't allow us to fode code that isn't commented or part of a cell or part of a function. We should be able to fold whatever we want!

Subject: Code folding

From: Loren Shure

Date: 3 Jun, 2009 11:14:51

Message: 8 of 15

In article <h040a6$rah$1@fred.mathworks.com>,
juliette.physicist@gmail.com says...
> Okay, it's been quite some time now and I still haven't found a way to fold my code. In fact, I can't even fold cells. I'd be extremely surprised if MATLAB doesn't allow us to fode code that isn't commented or part of a cell or part of a function. We should be able to fold whatever we want!
>

Post here to let us know what version of MATLAB you are using. Code
folding is relatively new in the editor.

--
Loren
http://blogs.mathworks.com/loren

Subject: Code folding

From: Michael Katz

Date: 3 Jun, 2009 17:48:36

Message: 9 of 15

If you have a recent MATLAB version, you might have to enable code folding
from File -> Preferences -> Editor -> Code Folding -> Enable code folding,
and make sure you enable folding for the constructs you are interested in.

Mike
http://blogs.mathworks.com/desktop

"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message
news:h040a6$rah$1@fred.mathworks.com...
> Okay, it's been quite some time now and I still haven't found a way to
> fold my code. In fact, I can't even fold cells. I'd be extremely
> surprised if MATLAB doesn't allow us to fode code that isn't commented or
> part of a cell or part of a function. We should be able to fold whatever
> we want!

Subject: Code folding

From: Juliette Salexa

Date: 3 Jun, 2009 19:42:02

Message: 10 of 15

Hello, I am using 7.5.0.342 (R2007b)

After clicking on "Preferences->Code folding" I have clicked "Ebable code folding" but the only two options I have are "function code" and "function help."

Loren Shure <loren@mathworks.com> wrote in message > Post here to let us know what version of MATLAB you are using. Code
> folding is relatively new in the editor.

Subject: Code folding

From: Michael Katz

Date: 3 Jun, 2009 19:54:51

Message: 11 of 15

Juliette,

We updated it in R2008a!
http://blogs.mathworks.com/desktop/2008/04/28/code-folding-update-in-r2008a/
Sorry for the confusion, I hope you are able to upgrade.

Mike

"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message
news:h06jm9$jg1$1@fred.mathworks.com...
> Hello, I am using 7.5.0.342 (R2007b)
>
> After clicking on "Preferences->Code folding" I have clicked "Ebable code
> folding" but the only two options I have are "function code" and "function
> help."
>
> Loren Shure <loren@mathworks.com> wrote in message > Post here to let us
> know what version of MATLAB you are using. Code
>> folding is relatively new in the editor.

Subject: Code folding

From: Juliette Salexa

Date: 3 Jun, 2009 22:28:01

Message: 12 of 15

Thanks,
I still find it strange though ..
My friend sent me an m-file that he made in Windows notepad. He didn't do any code folding or anything like that. And when I opened the M-file in my m-file editor, a block of commented code was folded, with the option to unfold it by choice. I asked him how he did it and he said "I didn't do anything, in fact it doesn't look like that in my editor (Windows notepad)."

Somehow his code was folded when I opened it, but I can't fold lines of commented code in my OWN m-files. Strange, no ??

"Michael Katz" <mkatz@mathworks.com> wrote in message <h06keb$9ft$1@fred.mathworks.com>...
> Juliette,
>
> We updated it in R2008a!
> http://blogs.mathworks.com/desktop/2008/04/28/code-folding-update-in-r2008a/
> Sorry for the confusion, I hope you are able to upgrade.
>
> Mike
>
> "Juliette Salexa" <juliette.physicist@gmail.com> wrote in message
> news:h06jm9$jg1$1@fred.mathworks.com...
> > Hello, I am using 7.5.0.342 (R2007b)
> >
> > After clicking on "Preferences->Code folding" I have clicked "Ebable code
> > folding" but the only two options I have are "function code" and "function
> > help."
> >
> > Loren Shure <loren@mathworks.com> wrote in message > Post here to let us
> > know what version of MATLAB you are using. Code
> >> folding is relatively new in the editor.
>

Subject: Code folding

From: Steve Amphlett

Date: 4 Jun, 2009 06:56:01

Message: 13 of 15

"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message <gvp175$4os$1@fred.mathworks.com>...
> When I go to preferences -> code folding, the only programming constructs that I can hide are "funciton code" and "function help"
>
> Also, I don't want my hidden code to be commented. By no means at all. The code is supposed to still be part of the running program, just not visible all the time as it takes up a lot of space and makes it hard to read. And I don't want to make it part of a function.

You could make it a script (not function).

Subject: Code folding

From: Juliette Salexa

Date: 4 Jun, 2009 16:33:02

Message: 14 of 15

Thank you Steve,
but I don't have a clue what you mean by that. I said I haven't been using functions at all, which (I think) means all my code is 'script' already.. Please correct me if I'm wrong.

"Steve Amphlett" <Firstname.Lastname@Where-I-Work.com> wrote in message > You could make it a script (not function).

Subject: Code folding

From: Sarah Hunt

Date: 19 Nov, 2010 16:17:04

Message: 15 of 15

"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message <h08svt$c4g$1@fred.mathworks.com>...
> Thank you Steve,
> but I don't have a clue what you mean by that. I said I haven't been using functions at all, which (I think) means all my code is 'script' already.. Please correct me if I'm wrong.
>
> "Steve Amphlett" <Firstname.Lastname@Where-I-Work.com> wrote in message > You could make it a script (not function).

Hi Juliette, Did you ever manage to find out how to fold your script?

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
editor Ned Gulley 8 Jun, 2009 17:13:15
rssFeed for this Thread

Contact us at files@mathworks.com