audiofilter/mex-it

Simplify creation of mex file for C++ function
128 Downloads
Updated 18 Mar 2022

Single header file library to automatically mex C++ functions for Matlab (with C++11 compiler)
supply the mex_function and let the compiler do the rest!
This supports basic C++ data types such as std::vector. Also Eigen Matrices and Vectors
How do the compiler know the inputs and outputs?
Non-const references mean outputs
Everything else are inputs
Example
Create a c++ implementation file like this
void mex_function(const double &x, const double &y, const double &z, double& result) {
result = (x + y)*z;
}
#include "mex-it.h"
Then build with CMake or using mex within Matlab
For single file example, you can do this in matlab (for recent GCC/Clang)
mex CXXFLAGS="\$CXXFLAGS -std=c++11" simple_example.cpp

Cite As

Tony Kirke (2024). audiofilter/mex-it (https://github.com/audiofilter/mex-it), GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Call C++ from MATLAB in Help Center and MATLAB Answers
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes
1.8.0.0

Better checking of data types for inputs

1.7.0.0

Check data types for input vectors so that 'float' isn't interpreted as 'double', etc

1.6.0.0

Fix compiler warnings for Windows

1.5.0.0

Now use single header file.

1.4.0.0

Update version number
Update Documentation

1.3.0.0

Bug fixes. Allow returning Eigen Vectors (as well as std::vector) to Matlab from mex
Update text

1.2.0.0

Add graphic

1.0.0.0

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.