To expand or collapse code, click the plus or minus sign that appears to the left of
the construct in the Editor. You can also press Ctrl+Shift+. (period) or Ctrl+. (period).
To expand or collapse all of the code in a file, place your cursor anywhere within the file,
right-click, and then select Code Folding > Expand All or Code Folding > Fold All
from the context menu. You can also press Ctrl+Shift+= or Ctrl+=.
NoteCode folding is not supported in the Live Editor
View Folded Code in a Tooltip
You can view code that is currently folded by positioning the pointer over its ellipsis.
The code appears in a tooltip.
The following image shows the tooltip that appears when you place the pointer over the
ellipsis on line 23 of lenghtofline.m when a for loop is folded.
Print Files with Collapsed Code
If you print a file with one or more collapsed constructs, those constructs are expanded in
the printed version of the file.
Code Folding Behavior for Functions that Have No Explicit End Statement
If you enable code folding for functions and a function in your code does not end with an
explicit end statement, you see the following behavior:
- If a line containing only comments appears at the end of such a function, then the
Editor does not include that line when folding the function. MATLAB does not include
Improve Code Readability