In a recent comment, Han Geerligs suggested we introduce #pragma-type directives to introduce arbitrary code folding. Well, we do have that, it’s called cells. You can introduce a cell by placing a %% at the beginning of a line. You may also need to turn code folding on for cells in order for this to work (see this blog entry for instructions). It’s not exactly the same as a #region, but it has some nice MATLAB-y features, such as evaluation and shading in the editor (see this blog entry for more info).
Other directives like the “#” compiler directive in MATLAB are indicated with the %# token. In R2008a, the MATLAB language supports the following directives:
- %#ok – suppress M-Lint messages
- %#eml – puts a M-file in to Embedded MATLAB mode
- %#function and %#external for the MATLAB compiler
Since these directives are also MATLAB comments, you can easily put additional comments on the same line explaining what the token is doing there.
Please don’t abuse cells for the sake of folding. If your code is too big, for your eyes’ sake, break up the file into separate functions.
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.