MATLAB Answers

How do I use the help command to display multi-line comments?

42 views (last 30 days)
Multi-line comments can be achieved using:
random foobars
However, whenever I place this at the top of a new script and try to call the help command, the output keeps on resulting in just:
Does this mean that the help command is limited to only single-line comments? I would assume that this was the case and call it a day but a textbook on MATLAB shows an example that prints out a multi-line comment using 'help'.
Walter Roberson
Walter Roberson on 3 Nov 2016
Sigh. I feel so old some days, my culture lost in time, like tears in the rain.

Sign in to comment.

Accepted Answer

Abhinav Gurram
Abhinav Gurram on 7 Nov 2016
The ability to add block comments to the help text of a function is not available in MATLAB.
MATLAB considers the group of consecutive lines immediately following the H1 line and those beginning with a % sign to be the online help text for the function. The H1 line is the first help text line that consists of comment text. Therefore, the H1 line begins with a % sign. The first line without a % sign as the left-most character ends the help.
In this case, as a block comment using the operators %{ and %} is added, the lines inside the block do not start with a % sign. Therefore, MATLAB considers the %{ line as the end of the help.
As an alternative, use a % sign at the beginning of each line instead of block comments. You can comment multiple lines by selecting them and using Ctrl + R. To uncomment them, select the group of lines, and use Ctrl + T.
Hope this helps!
  1 Comment
Aaron Kaw
Aaron Kaw on 20 Nov 2020
Yes this definitely helps.
But doesn't address ease of use. This multiline documentation feature exists in so many other languages already. The pain of manually adding a % for each newline I make gets irritating.
And using CTRL + R means we have to keep toggling with CTRL + T whenever we need to make major edits to the help documentation of each function/class/etc.
Additionally, CTRL + R places the comment symbol at the beginning of each line, not indented to the the needed position.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!