What's the difference between % and %% for comments?

前端 未结 3 1067
傲寒
傲寒 2021-02-13 06:35

The MATLAB editor automatically highlights all content after %% comments, and text after %% in the same line are turned bold. But what\'s the essential

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-13 06:57

    I really like the double percent sign (%%) and use as far as possible for the following reasons:

    1. Creates a cell block which could be run separately from the whole code (Ctrl + Enter).

    2. As mentioned in sections, it improves the readability of the file and appears as a heading if you publish your code. It increases concentration by creating a yellow background and you can focus more on the part that you are working on.

    3. You can fold the code in cell blocks. (First you should enable code folding of cell blocks in Preferences >> Editor/Debugger >> Code Folding >> Sections). This is useful specially in large mfiles.

    4. If you care about keeping a clean Command History running the codes in cell blocks (Ctrl + Enter) does not leave any trace in Command History , unlike the Evaluate Selection (F9) which evaluates the selected (highlighted) code and holds the executed code in Command History.

    Hope it helps.

提交回复
热议问题