为程序添加帮助
This example shows how to provide help for the programs you write. Help text appears in the Command Window when you use thehelp
function.
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 thefunction
keyword). If the function contains an参数
block, you also can position the help text immediately below the参数
block.
For example, create a function in a file namedaddme.m
that includes help text:
functionc = 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.switchnargincase2 c = a + b;case1 c = a + a;otherwisec = 0;end
When you typehelp addme
at the command line, the help text displays in the Command Window:
addmeAdd two values together. C =addme(A) adds A to itself. C =addme(A,B) adds A and B together. See alsosum,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 thehelp
andlookfor
functions use the H1 line to display information about the program.
CreateSee 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, thehelp
command displays each of these function names as a hyperlink to its help. Otherwise,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 HTMLanchor element. Within the anchor, use a
matlab:
statement to execute aweb
command. For example:
% For more information, see the MathWorks Web site.
End your help text with a blank line (without a%
). The help system ignores any comment lines that appear after the help text block.
Note
When multiple programs have the same name, thehelp
command determines which help text to display by applying the rules described inFunction Precedence Order. However, if a program has the same name as a MathWorks®function, theHelp on Selectionoption in context menus always displays documentation for the MathWorks function.