| Contents | Index |
| On this page… |
|---|
Help consists of lines of comments at the beginning of a program file. Help that you add to your file displays like the help for MATLAB functions. The first help text line, often called the H1 line, includes the function name and a brief description.
For example, here is an excerpt from the file hist.m:
function [no,xo] = hist(varargin) %HIST Histogram. % N = HIST(Y) bins the elements of Y into 10 equally spaced containers % and returns the number of elements in each container. If Y is a % matrix, HIST works down the columns. % % N = HIST(Y,M), where M is a scalar, uses M bins. % % N = HIST(Y,X), where X is a vector, returns the distribution of Y % among bins with centers specified by X. The first bin includes % data between -inf and the first center and the last bin % includes data between the last bin and inf. Note: Use HISTC if % it is more natural to specify bin edges instead. % % Class support for inputs Y, X: % float: double, single % % See also HISTC, MODE.
When you type help hist, the help text displays in the Command Window:
hist Histogram.
N = hist(Y) bins the elements of Y into 10 equally spaced containers
and returns the number of elements in each container. If Y is a
matrix, hist works down the columns.
N = hist(Y,M), where M is a scalar, uses M bins.
N = hist(Y,X), where X is a vector, returns the distribution of Y
among bins with centers specified by X. The first bin includes
data between -inf and the first center and the last bin
includes data between the last bin and inf. Note: Use HISTC if
it is more natural to specify bin edges instead.
Class support for inputs Y, X:
float: double, single
See also histc, mode.
Overloaded methods:
fints/hist
categorical/hist
Reference page in Help browser
doc histCreate See also links by including function names at the end of your help text on a line that begins with % See also. The list of names can include MATLAB functions, toolbox functions, and your own functions. If the function exists on the search path or in the current folder, the help command displays each of these function names as a hyperlink to its help. Otherwise, MATLAB prints the function names as they appear in the help text.
End your help text with a blank line (without a %).
You can include hyperlinks (in the form of URLs) to HTML files or Web sites anywhere in your help text. Create hyperlinks by including an HTML <A> </A> anchor element. Within the anchor, use a matlab: statement (pronounced matlabcolon) to execute a web command. For example:
% For more information, see <a href="matlab:
% web('http://www.mathworks.com')">the MathWorks Web site</a>.
When you are connected to the Internet and click the link, MATLAB opens a Web browser window to display the URL. For more information, see Display Hyperlinks in the Command Window.
For information about formatting help in the Editor, see Add Comments.
For related information, see Generating a Summary View of the Help Components in Functions and Scripts.
Provide a summary file for your own collection of program files using the same method as MATLAB. In MATLAB, each folder containing program files includes a file named Contents.m (with a capital C) that lists the functions in the folder with a brief description of each. You can view the information in a Contents.m file from the command line in several ways:
help foldername displays the text from the Contents.m file for that folder. The displayed help has hyperlinks to help for the individual functions.
doc foldername displays the same information in the Help browser.
ver toolboxname displays version information for the specified toolbox, followed by its formatted Contents.m file entries.
To create your own Contents.m files:
In the Editor, display a Contents.m file provided with MATLAB to see its structure. Most folders in the program tree contain a Contents.m file. For an example, see matlabroot\toolbox\matlab\helptools\Contents.m.
Read about Displaying and Updating a Report on the Contents of a Folder to learn how to easily create and maintain your Contents.m files.
Provide your own toolbox name, a version, and a date in the first two lines of the Contents.m file, which the ver function displays:
% Toolbox name description
% Version xxx dd-mmm-yyyyDo not include any spaces in the date. Use this format: 12-Mar-2010.
Tip If you do not want your users to see a summary of your toolbox functions, place an empty Contents.m file in the toolbox folder. An empty Contents.m causes help foldername to report No help found for foldername. |
The Upslope Area toolbox example folder contains a Contents.m file. For more information, see Learning to Add Help from Examples.
You can create a categorical listings of functions for the Help browser by marking up your Contents.m file and publishing it to HTML. To learn more, see Creating Function and Block Category Listings.
If you create your own MATLAB classes, you can provide help for the class by including comments in the class definition file:
Provide help about the class in comment lines directly following the classdef statement.
Add a comment line directly after the constructor method for the class.
Add comments directly after other methods and next to property definitions.
List the properties and methods of the class within the first block of comments after classdef. If you format the list in as described here, MATLAB renders the property and method names you list as hyperlinks to their definitions, which appear later in the same file:
To create links from this section to your class properties, add a line:
% Classname Properties:where Classname is the name from your classdef. Be sure to put a colon (:) after Properties.
List your property names (with optional same-line descriptions) on the following lines. For example:
% prop1 - first property % prop2 - second property
List the methods; enter the class name followed by Methods: (include a colon). Then, list your methods (with optional same-line descriptions) on the following lines, as follows:
% MyClass Methods: % method1 - first method % method2 - second method
View help for your class in the Command Window:
help classnameTo view the same help for the class in the Help browser, run:
doc classnameNote You do not need to prepare HTML versions of class definition file help. MATLAB generates an HTML page from each class definition automatically and displays it in the Help browser. |
For more information about getting help for classes, read the following section. To learn more about how to create class definitions, see User-Defined Classes.
The following example shows help for a class file, sads.m, an example provided with MATLAB documentation. If you create help for your class files, the help should look and work like this example.
Follow these steps to see the help for the example.
Make sure you can access the examples folder by either:
Making the folder containing the example file as your current folder:
cd(fullfile(matlabroot,'help','techdoc','matlab_env', 'examples'))
Adding the examples folder to the search path:
addpath(fullfile(matlabroot,'help','techdoc','matlab_env', 'examples'))
Or, Click here to add the help examples folder to the search path.
Open the class file in the Editor to see the help comments.
open('sads.m')View help for the sads class in the Help browser:
doc sads

Access more information by following links on the class help page or by using the doc function. For example, to get help for the steer method, do one of the following:
Click the steer link under Method Summary.
Run doc sads.steer.

You also can open the sads.m file by clicking the View code for sads link at the top of the sads help page, as described previously.
Next, view information about sads objects another way. Create an instance of sads, for example, sensorArray, and then open that object in the Variable Editor:
loadparameters sensorArray=sads(Data, Wavelength,SampleRate,Spacing,Name); openvar sensorArray % or double-click sensorArray in the Workspace browser

![]() | Types of Help You Can Create | Add Documentation to the Help Browser | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |