MATLAB Answers


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

さんによって質問されました 2012 年 4 月 4 日
最新アクティビティ Elia Cipriano さんによって コメントされました 2019 年 2 月 16 日
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.

  5 件のコメント

Dave Kooijman 2017 年 2 月 23 日
Works for me in MATLAB 2016b. The settings are under MATLAB > Editor/debugger > Code Folding.
2017 年 6 月 8 日
And if you right click anywhere in the code, the bottom section of the popup window is 'Cold Folding' > Fold All. Useful for a quick return to a high level view.
Elia Cipriano 2019 年 2 月 16 日
I put everything in a for loop for i=1:1 and then use it to collapse everything inside. Very easy

サインイン to comment.


2 件の回答

回答者: Daniel Shub
2012 年 4 月 4 日

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

  4 件のコメント

I can now put a section, but to add fold/unfold feature?
Saiprasad Gore 2017 年 11 月 10 日
@Soumitra Vadnerkar
I use Matlab R2016. In that I was able to enable fold/unfold, use following steps
Home tab > preferences > Editor/Debugger > code folding > sections
Linwei Hu
2018 年 5 月 8 日
This works perfectly. Thank you very much.

サインイン to comment.

回答者: Adam Spry
2017 年 3 月 18 日

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 件のコメント

I recently discovered this trick has its shortcomings. You can't define functions instead of control statements (even if it is just a loop that doesn't actually loop).
I wish that you could define the end of code sections so you could nest code sections inside of code sections.
Walter Roberson
2017 年 4 月 11 日
I think you mean "inside of control statements" rather than "instead of control statements" ?

サインイン to comment.

Translated by