The MATLAB editor automatically highlights all content after %%
comments, and text after %%
in the same line are turned bold. But what's the essential difference here? Why do people sometimes use %%
instead of %
?
相关问题
- Extract matrix elements using a vector of column i
- How do you get R's null and residual deviance
- How to display an image represented by three matri
- OpenCV - Is there an implementation of marker base
- Avoid copying an array when using mexCallMATLAB
相关文章
- How do I append metadata to an image in Matlab?
- How can I write-protect the Matlab language?
- `std::sin` is wrong in the last bit
- Escape sequence to display apostrophe in MATLAB
- Vertical line fit using polyfit
- Can the Pluggable Annotation Processor API retriev
- Reading .mat file using C: how to read cell-struct
- Insert HTML comments in React
From a syntax point of view, they are both comments.
In the Matlab editor, Matlab parses
%%
delimited blocks as "sections" which you can run as a unit independent of running the whole script.One percent sign (
%
) is used for commenting lines.Two percent signs (
%%
) have a different purpose: they are used for dividing your code into sections, which can be run independently. This allows easier debugging.I really like the double percent sign (
%%
) and use as far as possible for the following reasons:Creates a cell block which could be run separately from the whole code (Ctrl + Enter).
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.
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.
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.