MATLAB Language Useful tricks Code Folding Preferences

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

It is possible to change Code Folding preference to suit your need. Thus code folding can be set enable/unable for specific constructs (ex: if block, for loop, Sections ...).

To change folding preferences, go to Preferences -> Code Folding:

enter image description here

Then you can choose which part of the code can be folded.

Some information:

  • Note that you can also expand or collapse all of the code in a file by placing your cursor anywhere within the file, right-click, and then select Code Folding > Expand All or Code Folding > Fold All from the context menu.
  • Note that folding is persistent, in the sense that part of the code that has been expanded/collapsed will keep their status after Matlab or the m-file has been closed and is re-open.

Example: To enable folding for sections:

An interesting option is to enable to fold Sections. Sections are delimited by two percent signs (%%).

Example: To enable it check the "Sections" box:

enter image description here

Then instead of seeing a long source code similar to :

enter image description here

You will be able to fold sections to have a general overview of your code : enter image description here



Got any MATLAB Language Question?