File Exchange

image thumbnail

Using Doxygen with Matlab

version 1.8 (87.4 KB) by

Extracts automatically comments from your Matlab .m files using Doxygen to generate documentation

30 Ratings



View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

This package allows you to extract automatically comments from your Matlab .m files using Doxygen to generate documentation.

This package provides :
- a perl script ( used to filter the .m files so that Doxygen can understand them
- a template for the Doxyfile file (configuration file for Doxygen) which has to be modified according to the location of your code
- documentationGuidelines.m, an .m file which describes how you should comment your code so that Doxygen can extract it and create nice documentation
- classDocumentationExample.m : an .m file describing possible comment for classes
- all the documentation (html format) automatically generated by Doxygen from the two .m files (see Doc/html/index.html), which provides informations about installation and how to write Doxygen comments.

Installation details :
    - You need to have the Doxygen software installed (version 1.5.9 or newer required (tested with version 1.7.1))
    - You need to have perl installed (perl is shipped with Matlab, located usually in $matlabroot\sys\perl\win32\bin)
   - unzip the to C:\DoxygenMatlbab (for example)
    - get the Doxyfile file from the C:\DoxygenMatlbab directory and replace the default Doxyfile provided by Doxygen
    - edit the Doxyfile file (or use the DoxyWizard tool provided by Doxygen) to modify a few settings :
          o EXTENSION_MAPPING=.m=C++
          o FILTER_PATTERN=*m=C:\DoxygenMatlbab\
          o PERL_PATH=<path to your perl version>
          o INPUT=<directory where your documented code is located>
          o OUTPUT_DIRECTORY=<directory where you want to generate your documentation>
          o STRIP_FORM_PATH=<directory where your documented code is located>

Note for Windows users :
In certain circumstances, the association between .pl files and the perl executable is not well configured, leading to "Argument must contain filename -1 at C:\DoxygenMatlab\ line 4" when running doxygen. To work around this issue, you should execute the following lines in a Windows command prompt ("cmd") :

   assoc .pl=PerlScript
   ftype PerlScript=C:\Program Files\MATLAB\R2010b\sys\perl\win32\bin\perl.exe %1 %*
(don't forget to replace the path to the perl.exe file with yours in the line above)

Comments and Ratings (72)

Since this code has not been updated since 2011, I've update this code to a github repository. I hope people will contribute to it in terms of code and documentation.

Here is the code:

I'll try to include some of the patches proposed below.

Thom DeCarlo

Using this on OS X required a couple modifications.
1 - change "/usr/bin/perl.exe" to "/usr/bin/perl"
2 - run dos2unix on

Also, as noted on 18 Nov 2010 by Guillaume JACQUENOT, function declarations with continued lines ("...\n") do not work properly.

Otherwise, this script has been a great help!


Useful work, however it did not work well with namespaces. Here is my fix.

1. Add in the beginning of m2cpp following code

# Extract namespace
my $namespace = '';
foreach(split /\//, $fname) {
        if($_ =~ /^\+/) {
                $namespace = $namespace.substr($_, 1).'.';

2. Set $namespace as prefix to $className

Example: Replace
$classDef = "class ".$className.":public $classInheritance";
$classDef = "class ".$namespace.$className.":public $classInheritance";

The inherits are detected correctly and the list of classes is also grouped by namespace. I'm happy with the result.

Felipe Viana

Great contribution. Thanks!!!


I am generating a Doxygen documentaion for .m file.Firstly I generate it by simply editing the doxygen.conf file, I add FILE_PATTERNS= .m and EXTENSION_MAPPING= .m=c++. But it did not produce correct documentation of .m file. Now I am following your post "Using Doxygen with matlab and download "Doxygenmatlab" package. I have tried to understand all things, But unable to understand. Guide me what I have to do?


possible typos in the instructions and doxyfile. should be FILTER_PATTERNS

otherwise doxygen ignoring the tag


Ingo (view profile)

Great file, using it since a long time.

However, now finally changed to Windows 7 I get the error/warning message warning: "Warning: Found ';' while parsing initializer list! (doxygen could be confused by a macro call without semicolon)" and my .m files are not parsed any longer. Do anybody know the workaround?! (Sonsoles earlier had the same problem but didn´t posted the solution;-()

This script is great!

It would be fantastic to have also a method to generate the source browser correctly with the comments stripped.

I've tried to strip the comments from the source files with a perl filter used in FILTER_SOURCE_FILES. But then the hyperlinks from the documentation to the code are wrong.

Any suggestion on how to do this?


Steven (view profile)

I realized that comment in the function is not possible to extract by this filter even with "%>"
And function output parameter does not reveal in the documents also, if using a "..." for line break in the function name, the filter cannot parse it correctly.


Steven (view profile)

Cool and thanks! I finally make it work. Keep stuck at the error "Argument must contain filename"

I fix it using this solution

Option1 does not fix it well, but option2 does the trick.

Mark Mikofski

Mark Mikofski (view profile)


Thank you for creating this Fabrice.
I will take a look at it and provide feedback.



Eckard (view profile)

Hello Fabrice.

My name is Eckard Klotz. I\'m the developer behind the two sourceforge projects:
Moritz :
MuLanPa :

Both are open source freeware-projects and should be used as an extension of Doxygen to create algorithm describing diagrams like nassi shneiderman or uml activity diagrams.

Today in both projects.
The snapshot of the project Moritz
contains in the windows-distribution
in the folder LangPack\pascxal your filter. You will find in the file

The following paragraphs:

    Since this distribution contains doxygen-configurations also and
    with the version 1.9.08 the languages Matlab and Pascal are
    supported also two third-party filters are added in the associated
    LangPack folders:

     Author: Fabrice

     Filter: pas2dox.exe
     Author: Darren Bowles

I hope that this is OK for you but please don't hesitate to argue if you
have some doubts about this. You will find a forum-section in both projects.

Best regards,
                    Eckard Klotz.


Thanks Fabrice for your file.
Now it is working in my matlab but i want to know if with this GraphViz options are available. i mean class graphs and caller graphs among others.
Thanks again


Jason (view profile)

I had to update for line endings on my Mac. In VIM, I used ":set ff=unix" and that did the trick.


Hello!! i am runing Doxygen in my matlab code and the question is, it should show some graph as well.
i got the following errors:
C:/Users/Sonsoles/Documents/Fortran/Kompressorkoden/get_o_over_c.m:23: warning: Found ';' while parsing initializer list! (doxygen could be confused by a macro call without semicolon)
C:/Users/Sonsoles/Documents/Fortran/Kompressorkoden/get_omega_s.m:21: warning: Found ';' while parsing initializer list! (doxygen could be confused by a macro call without semicolon)
C:/Users/Sonsoles/Documents/Fortran/Kompressorkoden/Xfunc.m:21: warning: class for member `M::::::calculate:' cannot be found.
thanks for the help

I am under Windows XP R2011b. When I run Doxygen , the perl file shows up on the screen for each M-file that is processing. I have to close the file manually.
Moreover , your perl file requires to change all our syntax since the filter extracts only lines beginning with %>. For function description, same issue , we have to use a specific syntax.

The other submission "mtoc++ - Doxygen filter for Matlab and tools " is better , it doesn't require any change in our codes.

I definitely prefer m2html which is plug and play.

Håkan Håkan

Hello Fabrice!

Finally - poh - I have m2cpp running in Windows 8 with Matlab 7.0.4!

First I had problems with access rights for involved programs, had to set Run as administrator, also had to patch in registry to make perl accept command line arguments.

Then crashed at row 43. After having modified by inserting
"use FileHandle;" at first row
and replaced row 43
"open(my $in, $my_fic);"
my $in = new FileHandle; # Fix for old version of Perl
$in-> open($my_fic);

things run nicely!!!

Thanks for your submission
Håkan Fridén


Peter (view profile)

Question: Is this supposed to work for call graphs, like on M2HTML?

The *inheritance* graphs are being generated properly. But I don't see any call graphs for any of my functions or class methods.


Snowred Wang

ok I just found out that I have to use the \fn keyword with the input name written exactly the same as what m2cpp generates. For example, I need to add a line saying

%> \fn my_func_name(in par1,in par2)

Thanks for m2cpp a very nice work!

Snowred Wang

I'm trying to use it with doxygenwizard 1.8.2 under windows 7. I believe that I've followed all instructions but I just got an empty index.html page. What might be the problem? Below are my logs

Adding custom extension mapping: .m will be treated as language c++
Searching for include files...
Searching for example files...
Searching for images...
Searching for dot files...
Searching for msc files...
Searching for files to exclude
Searching for files to process...
Searching for files in directory C:/Project/xxx
Reading and parsing tag files
Preprocessing C:/Project/xxx/xxx1.m...
Parsing file C:/Project/xxx/xxx1.m...
Preprocessing C:/Project/xxx/xxx2.m...
Parsing file C:/Project/xxx/xxx2.m...
Building group list...
Building directory list...
Building namespace list...
Building file list...
Building class list...
Associating documentation with classes...
Computing nesting relations for classes...
Building example list...
Searching for enumerations...
Searching for documented typedefs...
Searching for members imported via using declarations...
Searching for included using directives...
Searching for documented variables...
Building member list...
Searching for friends...
Searching for documented defines...
Computing class inheritance relations...
Computing class usage relations...
Flushing cached template relations that have become invalid...
Creating members for template instances...
Computing class relations...
Add enum values to enums...
Searching for member function documentation...
Building page list...
Search for main page...
Computing page relations...
Determining the scope of groups...
Sorting lists...
Freeing entry tree
Determining which enums are documented
Computing member relations...
Building full member lists recursively...
Adding members to member groups.
Computing member references...
Inheriting documentation...
Generating disk names...
Adding source references...
Adding xrefitems...
Sorting member lists...
Computing dependencies between directories...
Generating citations page...
Counting data structures...
Resolving user defined references...
Finding anchors and sections in the documentation...
Combining using relations...
Adding members to index pages...
Generating style sheet...
Generating example documentation...
Generating file sources...
Generating file documentation...
Generating page documentation...
Generating group documentation...
Generating class documentation...
Generating namespace index...
Generating graph info page...
Generating directory documentation...
Generating index page...
Generating page index...
Generating module index...
Generating namespace index...
Generating namespace member index...
Generating annotated compound index...
Generating alphabetical compound index...
Generating hierarchical class index...
Generating member index...
Generating file index...
Generating file member index...
Generating example index...
finalizing index lists...
symbol cache used 16/65536 hits=192 misses=16
lookup cache used 0/65536 hits=0 misses=0
When enabling GENERATE_HTMLHELP the search engine (SEARCHENGINE) should be disabled. I'll do it for you.
*** Doxygen has finished

I really like the doxygen integration and I'll use it from now on.
Only a minor feature is missing from my point of view.

I would like to comment on class variables after the definition and not before. Is that somehow possible or is there a quick fix to enable the tool for that?

classdef CameraModel
        ImageSize = [640 480]; %> Camera image size in pixel [x y]

Sorry I'm not really familiar with perl so that I couldn't do it by myself.



Actually someone helped me already to solve the problem. The file is formatted for DOS. One has to reformat it for Linux in order to get everything to work correctly (I did it with the tofrodos package). The program is great :-)


It *almost* works for me and I suspect it may have to do with a Linux problem. I receive the following error messages

sh: /media/sda5/Giovanni/Utilities/Matlab_utilities/Matlab_exchange_downloads/DoxygenMatlab/ not found
and the html files after this do nto contain any documentation (as no c++-style comments are produced). The is there, though, I have tried to move it around and I still receive corresponding error messages. Could anyone tell me where I have to start looking for solving this problem? Thanks in advance.


Great contribution, thanks a lot!


Tom (view profile)

Dear Fabrice,
is your package able to document code that uses the old class specification (before use of "classdef")?

Thanks a lot,


Brian (view profile)


Eckard (view profile)

Hello everyone

I get an error by using the pearl-script like follows:

Reading and parsing tag files
Preprocessing D:/Daten/Projekt../src/fcn.m...
Can't use an undefined value as filehandle reference at D:\Daten\Projekt\..\Filter\ line 47 (formaly line 53).
Parsing file D:/Daten/Projekt/../src/fcn.m...

I tried to implent the patches from Bastian (07.07.2011) but the only the line-number changed from 43 to 47.

I use the pearl-version of Matlab 2009b on windows XP-SP3 together with Doxygen version 1.7.4

Thanks for your help,
                    Eckard Klotz.


thanks again for this wonderful script.

It would be a nice improvement to have some options to be able to hide some information in the documentation:
-> hide the Hidden methods/properties for the public APIs.
-> hide the set.my_property/get.my_property methods in the classes that are useless in the documentation


I have solved the previous package problem modifying the PERL script

at line 42 (after the foreach $my_fic)
$packages = "";
if ($my_fic =~ /^[^\+]*\+(.*)[\/\\].*\.m/g){
  $packages = $1.".";
  $packages =~ s/[\/\\]\+/\./g;

at lines 176 and 180 (when defining $classDef:
replace: $classDef = "class ".$className
by: $classDef = "class ".$package.$className

With this patch, your code will be compatible with the Matlab Packages!


Fabrice, thanks for this nice script.

However, is it possible to include support for packages?
For example, if you have:
where ChildClassName < PackageName.ClassName, then the script combined with Doxygen will create 2 different pages for ClassName:
- one for ClassName containing the definitions of all methods and properties
- one for PackageName.ClassName containing no definition at all (just the inheritance relational graph)

Maybe you could use C++ namespaces to solve this bug?
(or maybe Java packages are more suited to implement nested packages like ./+Package1/+Package2/MyClass.m)

thanks a lot in advance if you can help with this!

PS: for those like Cedric who have some troubles with the "< handle" inheritance, you must UPDATE your Doxygen installation :-)


Ian (view profile)

Wonderful interface to doxygen, very easy to implement.

One very small niggle is the shebang at the top of the perl script in the latest update points to perl.exe -- this needs to be edited before it will work on *nix / OS X...


LeFlaux (view profile)

Fabrice, thank you for your quick response. The flag was already set to YES. However, in the meantime I realized that doxygen works for private directories located in standard folders but not in class folders:

foo/private/stuff.m % works
foo/@myclass/stuff.m % works
foo/@myclass/private/stuff.m % won't appear in doxygen



Fabrice (view profile)

LeFlaux, I guess you problem is a Doxygen issue (maybe the EXTRACT_PRIVATE is set to NO in your Doxyfile). If not, could you send me a test case so that I can reproduce your problem ?


LeFlaux (view profile)

Dear Fabrice,

thank you for this great and useful piece of software! Just one little question: I got directories named `private' in my Matlab-project. The documentation of .m files contained in such directories are not displayed. Any suggestions?


The same problem (see the post of the 11 Mar 2011) happens when the attribute name begins with "end" (for instance "endDate").


Thx a lot for this great tool !


I experienced a little problem when using it on "@" folder class definition. As strange as it looks, when the name of my function (defined in an external .m file inside the @ folder) begins with a "m" letter, the function does not appear in the generated class description. It works just fine when I change it in another letter. Any idea?

Evgeny Pr

Evgeny Pr (view profile)

Hi Fabrice,

I noticed a small problem. At multiple inheritance from a class from a package-directory the base class name is defined incorrectly.

For example:
+My - package-directory
BaseClass.m - base class in +My directory
SomeClass.m - some class in +My directory

"SomeClass" define:
classdef SomeClass < My.BaseClass

When you create a documentation obtained that SomeClass is inherited from the "My", a not from "My.BaseClass" or "BaseClass". :)


Fabrice (view profile)

Hi Cedric,

- the inheritance syntax (classdef MyClass < handle) is fully supported by the script : could you send me a test file so that I can see why you experienced such errors using this syntax ?
- your second problem is an encoding configuration issue in your Doxyfile (you shouldn't use the UTF-8 encoding but probably the ISO8859-1 encoding)



It seems good, however I do encounter some problems: one of my scripts is a classdef deriving from 'handle' :
classdef MyClass < handle
the parser gives an error since < is not closed by a >
Is there a way to avoid this ?
Another problem is that the parser gives errors on non-ascii letters (é, è, ...)


Jack (view profile)

I've been using and enjoying your product. I have a quick question though.
1)I am using Matlab 2007a with only fuctions, i.e., not classes. I cannot get doxygen to create any graphs, either using graphviz or the included graphing library. I'm familiar with doxygen, and was wondering if your product in conjunction with doxygen supports graph generation via function calls alone? I uses a similiar perl script posted somewhere online to convert from .m to .c and it could generate graphs in doxygen. Thank you for your time, the .m is included below, in which no graph is generated (I have graph generation enabled in doxygen and all the setting in expert are correct aslwell I believe).
%> @brief Brief description of the function
   %> More detailed description.
   %> \latexonly
   %> $\bigl(\begin{smallmatrix}
   %> a&b\\ c&d
   %> \end{smallmatrix} \bigr)$
   %> \endlatexonly
   %> @param arg1 First argument
   %> @param arg2 Second argument
   %> @retval out1 return value for the first output variable
   %> @retval out2
   % ======================================================================
   function [out1, out2] = hhh( arg1, arg2)
     out1 = arg2;
     out2 = arg1;
     c = fb(out1);

   % ======================================================================
   %> @brief Brief description of the function
   %> More detailed description.
   %> \latexonly
   %> $\bigl(\begin{smallmatrix}
   %> a&b\\ c&d
   %> \end{smallmatrix} \bigr)$
   %> \endlatexonly
   %> @param arg1 First argument
   %> @retval out1 return value for the first output variable
   % ======================================================================
   function [out1] = fb( arg1)
     out1 = arg2;
2) when I use
/endlatex only
Doxygen commands to put in a matrix in latex, my matrices/equations have the "///" comment denoted for c++, this is not a problem, but if there is an easy fix I'll like to know.

Thanks for the update, Fabrice! Works perfect.
Linux users may find my tweaked Doxyfile for this tool useful:

By the way, does anybody know how to add citations to the documentation from Doxygen using LaTeX? I mean, one have \cite commands in the documentation, and those cited sources should appear in the doxygen-generated docs. Any ideas?


LeFlaux (view profile)

Just awesome! :) Thank You very much for this tool!

Note on Linux users should change the first line to

This seems a good function.

I notice a small bug

When I declare a function on several lines, the different arguments are not recognized

For example, something like this will produce warning, and won't be correctly displayed

%> @param AAAAAA
%> @param BBBBBBBB
%> @param CCCC
%> @param DDDDDDDD
%> @param EEEEEEEEEE
%> @retval Res return value for the first output variable
%> @retval RTex return value for the second output variable

function [Res,RTex] = Compute_residual(AAAAAA,BBBBBBBB,...


Fabrice (view profile)

I have just updated the script to better support :
- @-folder class definition
- multiple class inheritance (classdef a < b & c)
- classes attributes (Sealed, Hidden,...)
- events (transformed into enum Events in the generated documentation)
- private / protected / pubic methods
- private / protected / pubic properties
- constant properties (with their initialization)
- abstract classes (transformed into virtual functions in the generated documentation)
- the ignored argument (~) in function declaration is now read and transformed into an ignoredArg in the generated documentation

Evgeny Pr

Evgeny Pr (view profile)

Fabrice, please, update your files on fileexchange. Last version works fine!

Simon Prince

Great utility, thanks. Question about using it with multiple-file classes - I get it to work with a class in a single file, but when I set up a class in an @folder, I don't seem to get the function based methods (in separate files) located within my doxygen derived class.


Another strange point with inheritance. Imagine class Father inherited by two classes Son1 and Son2. In Father there is a method Father::doIt() overloaded by Son1::doIt(), but inherited directly from Father by Son2.
The strange point is that in Son2 documentation you’ll see comments about Father::doIt() (that is normal) followed by «Reimplemented in Son1» (that is weird — or may be this is a standard C++ documentation agreement ?)


I mean, with a brief form of abstract methods. With the following example :

    methods (Abstract)
        function calcPMInitiale(obj)
        projection(obj, iteration)

The first method will be detected, but not the second (correct definition for MatLab).


But I think it doesn't work properly with abstract methods...


Evgeny Pr

Evgeny Pr (view profile)

A small correction to define classes (classdef (Hidden, Sealed) SomeClass) are handled correctly:
if (/(^\s*classdef)\s*(\s*\([\w,\s]+\s*\))?\s*([\w\d_]+)\s*<?\s*([\w\d_]+)?(.*)/)

Evgeny Pr

Evgeny Pr (view profile)

I think the problem with this line in the file "m2cpp pl":
if (/(^\s*classdef)\s*(\s*\(Enumeration\s*\))?\s*([\w\d_]+)\s*<?\s*([\w\d_]+)?(.*)/)

"Enumeration" is undocumented attribute?
I've corrected as follows:
if (/(^\s*classdef)\s*(\s*\([\w]+\s*\))?\s*([\w\d_]+)\s*<?\s*([\w\d_]+)?(.*)/)

and added the else condition:
 $className = $3;
 $classDef = "class ".$className.":public $4";

This works, but I think it is not quite correct.

Evgeny Pr

Evgeny Pr (view profile)


I've found a bug.
Define a class with attributes:
classdef (Hidden) SomeClass < handle
...or with any other class attribute.
Such a definition is Parsed incorrectly.

Fabrice, You could fix this bug?
I don't understand anything in Perl. :)

Evgeny Pr

Evgeny Pr (view profile)

Do not use Perl, which comes with Matlab! It does not work correctly. Use ActivePerl.

Thank you, Fabrice, for a really nice tool! It seems, as Felix has noted, that only classes contained in one single .m-file are supported, and not the folder (@-)structure. Furthermore, the private class-properties are displayed as public ones. Is there any chance that you could fix this? I'm aware that the Matlab style of Access, SetAccess, and GetAccess might be tricky, but it would be really helpful. Thanks a lot!


Mike (view profile)

Does this tool handle collaboration diagrams? When a class is composed using another class, it does not show up in the collaboration diagram. The collaboration diagram is always the same as the class diagram. Am I doing something wrong?


Felix (view profile)

Thank you very much for this great tool.

Could it be that class hierarchies are not properly detected when the classes are in a package?

    Thanks for looking in to this, changing the extension from m to .m fixed the problem with 1.7.1.


Fabrice (view profile)

I tried to use Doxygen 1.7.1 and I suppose I reproduced your problem.
I guess this is a Doxygen bug, but as a workaround, you could try to change the value of EXTENSION_MAPPING in the Doxyfile :
EXTENSION_MAPPING=.m=C++ (don't forget the dot before the 'm').
Could you tell me if it solved your problem ?

Very nice tool - many thanks!
I found I had to use Doxygen 1.6.1, not 1.7.1 (latest).
I see from
you've seen something similar before.


Fabrice (view profile)

I changed the file so that unix users can use it.
Thanks for your feedback.


Ed (view profile)

I had a problem using the script under Unix (Linux) since the first line of the perl script, which defines the interpreter to use (/usr/bin/perl), was terminated using a carriage-return (\r) instead of a line feed (\n). Because of this the perl interpreter could not be found. Since the first line only makes sense in a Unix environment, I think the line-ending character for the first line (at least) should be changed to a line-feed.


Fabrice (view profile)

Mike, you can comment only variables outside function block (this is a Doxygen limitation), that is :
- arguments passed to functions, for example :
%> @brief Description of the foo function
%> @param a this is a description of var a
%> @param b this is a description of var b
function foo(a, b)

- properties in a classdef definition, for example :
classdef foo
    %> this is a description of the var a
    %> this is a description of the var b

Fabrice, thank for the program!
The only question I have: is it possible to comment variables by such script? I mean, if I have

a = [1,2,3,4]; %> this is a description of the var

can it be displayed in doxygen-generated docs?


Fabrice (view profile)


Maybe your perl exe is not properly installed (it seems it is the case for the perl provided by Matlab). You could try the following workarounds :

1. Set the following variables in the Doxyfile :

2. If it doesn't work you should try to install ActivePerl : with this version of perl, everything is working fine.


Why I got the following message? "Argument must contain filename -1 at C:\Users\user\Desktop\DoxygenMatlab\ line 4"


Nice! Would be useful if it can also generate enum classes by handling something like this,

classdef(Enumeration) Color < int32





This is exactly what I was looking for, and to see that it works on subfunctions and object oriented code is simply brilliant. This is a wonderful replacement to mtoc that works wonderfully. Many kudos to the author for simplifying my life and increasing my productivity. Brilliant!



Fixed a few bugs :
- property names (and method names) beginning with end are now allowed (as pointed out by Vincent)
- inheritance with classes containing a dot is now supported (as pointed out by Evgeni Pr)


Added support for :
* @-folder for classes
* multiple inheritance
* class attributes
* private / protected / public properties and methods
* abstract methods
* constant properties
* events
* ignored arguments (~)

MATLAB Release
MATLAB 7.6 (R2008a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video