Main Content

Debug on Microsoft Windows Platforms

This example shows the general steps to debug yprime.c, found in your matlabroot/extern/examples/mex/ folder. Refer to your Microsoft® documentation for specific information about using Visual Studio®. For an example, see How can I debug a MEX file on Microsoft Windows Platforms with Microsoft Visual Studio 2017?

  1. Make sure Visual Studio is your selected C compiler:

    cc = mex.getCompilerConfigurations('C','Selected');
  2. Compile the source MEX file with the -g option, which builds the file with debugging symbols included. For example:

    mex -g yprime.c

  3. Start Visual Studio. Do not exit your MATLAB® session.

  4. Refer to your Visual Studio documentation for information about attaching the MATLAB process.

  5. Refer to your Visual Studio documentation for setting breakpoints in code.

  6. Open MATLAB and type:


    yprime.c is opened in the Visual Studio debugger at the first breakpoint.

  7. If you select Debug > Continue, MATLAB displays:

    ans =
        2.0000    8.9685    4.0000   -1.0947

Related Topics