Matlab C and C++ MEX setup

Demonstrate that Matlab MEX C / C++ compiler wrapper is working on your system with the following commands. Ensure you are using a supported compiler with Matlab as the supported compilers are distinct across operating systems. These commands are all from within Matlab.

Setup Matlab C / C++ compiler

Setup Matlab with C and C++ compilers by:

mex -setup -v

mex -setup -v C++

Verify configuration by:

mex.getCompilerConfigurations('C')

mex.getCompilerConfigurations('C++')

Example C MEX

  1. Copy the Matlab example code:

    copyfile(fullfile(matlabroot,'extern','examples','mex','yprime.c'), pwd)
    
  2. compile

    mex yprime.c
    
  3. use the compiled code

    yprime(3,[4,2,7,1])
    

    which returns

    ans = 2.0000 5.9924 1.0000 2.986

Notes

if you get missing compiler errors, do MEX troubleshooting