Is there a way to 'fold up' sections of code - like when you close up a for loop
이전 댓글 표시
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
Matt Fig
2012년 11월 2일
Tom's question
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.
Yahor28
2017년 2월 3일
Accepted answer doesn't seem to work in MATLAB 2016a live script. Any ideas?
Dave Kooijman
2017년 2월 23일
Works for me in MATLAB 2016b. The settings are under MATLAB > Editor/debugger > Code Folding.
KAE
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
Kelvin Prosyk
2021년 7월 9일
편집: Kelvin Prosyk
2021년 7월 9일
Inserting artificial code loops inserts extraneous code and reduces readability if the code is published. The drawback of the existing %% code section approach is there is no end-section marker. It means you can't create an isolated code section in the same way as code blocks like a for loop. I'd love to seem Mathworks introduce a system of %%<section_start> and %%<section_end> tags.
Eric Daigrepont
2022년 1월 23일
편집: Eric Daigrepont
2022년 1월 23일
@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.
채택된 답변
추가 답변 (2개)
Ethan Duckworth
2021년 2월 25일
4 개 추천
FYI code folding does not work for Live Scripts
Adam Spry
2017년 3월 18일
Try this:
for d = 1
[Your code here]
end
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
Christopher Goodrich
2017년 4월 11일
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" ?
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!