Speed Up Your Code with C++
In certain cases, MATLAB code may be slow. Especially, when loops are involved. Vectorization might be a solution to this. However, this is not always possible. Moreover, vectorized code tends to be less human-readable and makes it hard for other people to understand your code. Instead, writing a C/C++ version of the considered MATLAB code can be a serious alternative.
A fast C/C++ implementation of a MATLAB function makes in particular sense for system models/measurement models or likelihood functions. These are called many times during state estimation, and a reduced execution time of the models will likely have a large impact on the runtime. For example, when evaluating several estimators in hundreds of runs using models implemented in C/C++ can reduce the total evaluation runtime drastically.
For those reasons, we provide a mechanism to easily use the powerful Eigen linear algebra library within MATLAB. It is directly shipped with the toolbox! There is no need for extra downloads or installation procedures. Eigen makes heavy use of SIMD (single instruction multiple data) instructions like SSE and tries to optimize (composed) matrix operations as much as possible during compile time. Thanks to wrapper classes, matrix data from MATLAB can effectively processed by Eigen.
Working with MEX files requires a properly configured C++ compiler (e.g., an installed Microsoft Visual Studio or GCC). For more information see Supported and Compatible Compilers.
The following example code can be found in the toolbox's examples.