This example shows how to provide help for the programs you
write. Help text appears in the Command Window when you use the
Create help text by inserting comments at the beginning of your
program. If your program includes a function, position the help text
immediately below the function definition line (the line with the
For example, create a function in a file named
includes help text:
function c = addme(a,b) % ADDME Add two values together. % C = ADDME(A) adds A to itself. % C = ADDME(A,B) adds A and B together. % % See also SUM, PLUS. switch nargin case 2 c = a + b; case 1 c = a + a; otherwise c = 0; end
When you type
help addme at the command line,
the help text displays in the Command Window:
addme Add two values together. C = addme(A) adds A to itself. C = addme(A,B) adds A and B together. See also sum, plus.
The first help text line, often called the H1 line, typically
includes the program name and a brief description. The Current Folder
browser and the
use the H1 line to display information about the program.
See also links by including function
names at the end of your help text on a line that begins with
See also. If the function exists on the
search path or in the current folder, the
displays each of these function names as a hyperlink to its help.
help prints the function names as
they appear in the help text.
You can include hyperlinks (in the form of URLs) to Web sites
in your help text. Create hyperlinks by including an HTML
element. Within the anchor, use a
to execute a
web command. For example:
% For more information, see <a href="matlab: % web('http://www.mathworks.com')">the MathWorks Web site</a>.
End your help text with a blank line (without a
The help system ignores any comment lines that appear after the help
When multiple programs have the same name, the
determines which help text to display by applying the rules described
in Function Precedence Order. However, if a program has
the same name as a MathWorks® function, the Help
on Selection option in context menus always displays
documentation for the MathWorks function.