Is there a way to 'fold up' sections of code - like when you close up a for loop

657 visualizzazioni (ultimi 30 giorni)
Is there a way to hide sections of code - like when you close up a for loop?
I have quite a long code with a few different sections, and while I'm working on one section I'd like to hide the other sections so the code is a bit more manageable to get around.
  7 Commenti
Eric Daigrepont
Eric Daigrepont il 23 Gen 2022
Modificato: Eric Daigrepont il 23 Gen 2022
@Kevlin Prosyk, I agree wholeheartedly. I try to use "%%" to held organize collapsible sections, but the auto-end-section significantly limits the ability to manage sections due to erratic updates and inconsistent operation. Frankly, one of the earliest languages I ever used, Pascal maybe, used "//" to comment the remainder of the line, and "/* ... */" to comment sections. I've been annoyed by any language since that did not allow the programmer to comment sections. And with the added benefit of modern code-folding,... controlling exactly how you'd like to fold you sections would add wonderfully for those of us love of clean, organized code.

Accedi per commentare.

Risposta accettata

Daniel Shub
Daniel Shub il 4 Apr 2012
Under preferences you can enable code folding for blocks. Blocks are defined in MATLAB as sections starting with %% (I am not sure if they can have anything else on the line).
So you should be able to fold
  8 Commenti
FastCar il 2 Ott 2022
Many thanks Daniel. I have logged in only to say this. You made my day!

Accedi per commentare.

Più risposte (2)

Adam Spry
Adam Spry il 18 Mar 2017
Try this:
for d = 1
[Your code here]
its collapsable on demand and doesn't effect the code at all (someone please correct me if I'm wrong). It can be used as many times as you like for each section of the code.
  2 Commenti
Walter Roberson
Walter Roberson il 11 Apr 2017
I think you mean "inside of control statements" rather than "instead of control statements" ?

Accedi per commentare.

Ethan Duckworth
Ethan Duckworth il 25 Feb 2021


Scopri di più su Loops and Conditional Statements in Help Center e File Exchange


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by