Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Code folding
Replies: 16   Last Post: Aug 12, 2014 9:33 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
John D'Errico

Posts: 9,053
Registered: 12/7/04
Re: Code folding
Posted: Aug 12, 2014 9:33 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Jason " <jason_liu9@yahoo.com> wrote in message <lscfm6$3h9$1@newscl01ah.mathworks.com>...
> "Sarah Hunt" <sarah0674115@hotmail.co.uk> wrote in message <ic67u0$92g$1@fred.mathworks.com>...
> > "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?

>
>
> Hey, an easy shortcut to folding your cold is to put whatever block you'd like to fold in a simple for loop
>
> For i=1
> %code code code; watch out for the usage of your loop variable i
> end
>
> Then, assuming that you have a new enough version of Matlab, you can click + or - next to the for loop to hide the entire loop.


You CAN do this, but it is not something I'd advise. It makes
your code more difficult to read. Why did I put that loop there?
What does that end statement correspond to? It creates a
spurious variable, here i. Worse, the variable i is already defined
in MATLAB. So you may have just created an inadvertant bug.

Adding an extra for loop is silly, when you can do the same
thing by putting %% comments before and after the block you
might wish to fold. Then enable code folding for sections in the
preferences pane for the editor.

NEVER make your code less readable.

John



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.