Generating HTML Documentation for Matlab


Chris Sharpe


Matlab, Documentation Tool

Review Status



The M2HTML is a tool for generating highly professional documentation in HTML page format for MATLAB source code (rather like Javadoc for Java or Doxygen for C++), which can be readily viewed online. It enables a user to easily to view and navigate a complex MATLAB project and gain a quick understanding of the inter-relationship and dependencies between code blocks. This is a guide for installing and running the tool. For more information, click on the following link to see a review of the tool from MATLAB Central at, MATLAB Central File Exchange. Online documentation and help can be found at, M2HTML Documentation. A very nice example of this tool in action can be found at, M2HTML Example.

M2HTML was originally developed by Guillame Flandin. It is entirely free.

Feature List

This is a list of the key features of the M2HTML tool.
• Online documentation - The tool parses all your M files to generate a set of HTML pages, which you can navigate via a web browser.

• Fully Indexed - A master index page is created for quick look-up and navigation of M files contained in a project. M files are listed alphabetically and divided by M file type. Individual HTML pages are created for each M file and clearly shows such information as function name, function arguments, header comments for the code, the source code in full (numbered and highlighted), and lists all external functions called by that function.

• Dependency Graph - A graph is generated that graphically represents function call dependencies for all functions in a project, including conceptual partitioning of system/project subsections by each file in a directory.

• Extensible - You are able to build your own templates and structure and create documentation in the way you want.

• Easy to Use - Once the tool has been installed, it is simply a matter of opening up MATLAB and calling the program from the command line.


The tool can be downloaded it from MATLAB Central. Copy and paste to the root directory of where your MATLAB
source files are kept. For example, if you have your source files stored in a directory C:/Documents/MATLAB, then put the zip file into the /MATLAB directory. (An limitation of the tool is that it must be launched one directory above from where your project files are stored.) Unzip the zip file; you should now have a file called m2html containing several files and directories.


There is a full description of how to execute the tool available from the online documentation, which you are advised to look at first. An additional example isalso worked through here. Assume we have several directories containing MATLABsource code stored at C:/Documents/MATLAB and we want to produce documentationfor one of these directories called MyProject.

• Open MATLAB and at the command line add the full path where the tool resides. The command in this example would be,

addpath C:/Documents/MATLAB/m2html.

• Change the working directory from the command line is it points at your source directory. The command in this example would be,

cd C:/Documents/MATLAB.

Now generate documentation for source files stored at C:/Documents/MATLAB/MyProject and output it to a file at C:/Documents/MATLAB/Documents/MyProject.The command in this example would be,


The first argument is the file type to process; the second argument is the directory to process; the third argument is the output format type; and the final argument is the location for the documentation. (In this example, the actual documentation will be stored at, C:/Documents/MATLAB/Documents/Documenation/MyProject.)

If you have several sub directories in MyProject, add the following parameter to the command line,


• For a full list of command line arguments is available by entering,

help m2html.

• To create the dependency graph, you’ll need to install the dot tool from Graph Viz.
Once installed, the command in this example would be,


Further information shall be added to this guide, especially for generating templates.

Internal Links

Related Articles

External links

Program Download: MATLAB Central File Exchange.
Online documentation: M2HTML Documentation.
An example of the tool, M2HTML Example.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License