Add Help for Your Program
This example shows how to provide help for the programs you write. Help text appears in
the Command Window when you use the help 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 the function keyword).
For example, create a function in a file named addme.m that 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 help and lookfor functions use
the H1 line to display information about the program.
Create 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
20 Function Basics