Main Content

为程序添加帮助

This example shows how to provide help for the programs you write. Help text appears in the Command Window when you use thehelpfunction.

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 thefunctionkeyword). 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.mthat 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 addmeat 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 thehelpandlookforfunctions use the H1 line to display information about the program.

CreateSee alsolinks 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, thehelpcommand displays each of these function names as a hyperlink to its help. Otherwise,helpprints 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 amatlab:statement to execute awebcommand. 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, thehelpcommand 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.

See Also

|

相关的话题