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:



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


    which returns

    ans = 2.0000 5.9924 1.0000 2.986


if you get missing compiler errors, do MEX troubleshooting