matlab2cpp Documentation
Release 0.5
Jonathan Feinberg
October 13, 2016
CONTENTS
1 User Manual 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 User interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Configuring translation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4 Translation rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.5 Behind the frontends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2 Developer Manual 21
2.1 Module overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.2 Quick translation functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.3 The tree constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.4 Node representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
2.5 Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
2.6 Auto-configure datatype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
2.7 Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
2.8 Translation rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
2.9 Datatype scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
2.10 Testsuite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Python Module Index 79
Index 81
i
ii
CHAPTER
ONE
USER MANUAL
1.1 Introduction
matlab2cpp is a semi-automatic tool for converting code from Matlab to C++. At the moment, matlab2cpp is the name
of the python module while m2cpp is the name of the python script. m2cpp is found in the root folder. When installing
the matlab2cpp module, the python script is copied to a system folder so that the script is available in path. Then the
m2cpp script can be executed by typing “m2cpp” in the command line interface (cmd in Windows, terminal in Linux).
Note that it is not meant as a complete tool for creating runnable C++ code. For example, the eval-function can not
be supported because there is no general way to implement it in C++. Instead the program is aimed as a support tool,
which aims at speed up the conversion process as much as possible for a user that needs to convert Matlab programs by
hand anyway. The software does this by converting the basic structures of the Matlab-program (functions, branches,
loops, etc.), adds variable declarations, and for some simple code, do a complete translation. And any problem the
program encounters during conversion will be written in a log-file. From there manual conversions can be done by
hand.
Currently, the code will not convert the large library collection of functions that Matlab currently possesses. However,
there is no reason for the code not to support these features in time. The extension library is easy to extend.
1.1.1 Installation
Requirements:
• Python 2.7.3
• Armadillo (Not required for running, but generator creates armadillo code.)
• C++11 (Plotting and TBB require C++11)
Optional:
• TBB
• Sphinx (for compiling documentation)
• Argcomplete (for tab-completion support)
Linux/Mac:
As root, run the following command:
$ python setup.py install
In addition to installing the matlab2cpp module, the executable ´m2cpp´ is copied to “/usr/local/bin/” The executable
´m2cpp´ is now available from path.
Windows:
1