Main Content

Debug on Microsoft Windows Platforms

This example shows the general steps to debug yprime.c, found in your MATLAB® fullfile(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 C MEX file on Microsoft Windows Platforms with Microsoft Visual Studio?

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

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

    copyfile(fullfile(matlabroot,"extern","examples","mex","yprime.c"),".","f")
    mex -g yprime.c

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

  4. Get the MATLAB process ID pid. (since R2025a)

    pid = matlabProcessID
  5. Refer to your Visual Studio documentation for information about attaching the MATLAB process ID.

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

  7. Open MATLAB and type:

    yprime(1,1:4)

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

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

    ans =
    
        2.0000    8.9685    4.0000   -1.0947
    

See Also

Topics