In Matlab, MEX files (MATLAB executable) allow the execution of their code in C / C + + or Fortran directly from MATLAB as if they were built-in functions or routines. The main advantages are essentially two: the ability to use code written in C / C + + or Fortran, without the need to rewrite it as a script m-file, in addition, improved efficiency of the code (especially in loops) on the execution time.
The initialization of the build system is running mex-setup
from the Matlab prompt.
On Windows, we support a variety of compilers, like Borland and Microsoft, but here we are interested in configuring the system to use GNU tools and / or open-source, which are not present in native system. We can opt for MinGW or Cygwin for , we preferred the first.
Once you install the compiler with all the libraries, checked the environment variables are correctly configured, the configuration of the gaming mex pass through a convenient utility gnumex .
This utility is going to create the script that is invoked for each mexopts.bat compilation, invoking, with the right parameters, the compiler gcc.
If all goes well, it should be possible to compile a sample code provided with Matlab:
yprime.c
mex functions yprime.dll implemented in the new library, generated from the compilation of C code, may be invoked as the usual functions of Matlab:
yprime (1,1:4) ans =
2.0000 8.9685 4.0000
-1.0947
More information:
- MEX-file from the site guides mathworks.com
- Gnumex, Mex-file with mingw
0 comments:
Post a Comment