MATLAB Community

MATLAB, community & more

MATLAB pragmas

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:

  1. %#ok – suppress M-Lint messages
  2. %#eml – puts a M-file in to Embedded MATLAB mode
  3. %#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.

|
  • print

评论

要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。