Is there a way to create "sub-folding" / "sub-sections"?

37 Ansichten (letzte 30 Tage)
Mark Golberg
Mark Golberg am 6 Okt. 2021
Kommentiert: Andre Zeug am 18 Okt. 2024
Hi,
I know I can create sections in my script editor with
%%
Question is, can I make several layers of 'sectioning'?
I mean, similar to headings in WORD...
Something like:
%%_1
%%_1.1
%%_1.1.1
that way I could organize, divide & fold my code as I please...
Thank you!

Antworten (2)

Darren Woods
Darren Woods am 7 Jun. 2024
Raising this thread again.
Other IDEs, such as Spyder for python, allow for the use of multiple subsection levels, e.g. %%, %%%, %%%%. These are conveniently indented in the code outline pane and all levels can be expanded and collapsed. Not so in Matlab? This seems like an easy functionality to add.
Cheers,
Darren.

Prateek Rai
Prateek Rai am 8 Okt. 2021
To my understanding, you want to make several layers of sectioning in a MATLAB script.
This is possible when you have loop (such as for loop), conditional statement (such as an if statement) or functions in the script.
You can refer to Create and Run Sections in Code MathWorks documentation page to learn more on the behavior of sections in functions or behavior of sections in loops and conditional statements.
  2 Kommentare
Mark Golberg
Mark Golberg am 10 Okt. 2021
Thank you @Prateek Rai
Indeed I'd like to have several layers of sectioning in my MATLAB script.
But! Point is, I don't want to restrict my self only to loops , ifs , etc...
I want to have a complete freedom in defining my layers (again, similar, to writing document in WORD).
For example, I could have a code doing some Task 1.
Below that there is a section of Task 1.1
Below that there is a section of Task 1.1.1 & Task 1.1.2 & Task 1.1.3 & etc...
I'd like to have the possibilty to fold ALL the code below Task 1.1 (would hide 1.1.1 - 1.1.1)
OR
fold only 1.1.1 & 1.1.2 - and continue working on 1.1.3
Does it make more sense now?
Andre Zeug
Andre Zeug am 18 Okt. 2024
As workaround I do:
%% Section (1)
...
if 1
%% Subsection (1.1)
...
%% Subsection (1.2)
...
end
%% Section (2)
...
This increases the readability of my code (when using code folding).

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by