Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: Code folding
Posted:
Aug 12, 2014 9:33 AM


"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@WhereIWork.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



