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?
Make sure Visual Studio is your selected C compiler:
cc = mex.getCompilerConfigurations("C","Selected"); cc.Name
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
Start Visual Studio. Do not exit your MATLAB session.
Get the MATLAB process ID
pid
. (since R2025a)pid = matlabProcessID
Refer to your Visual Studio documentation for information about attaching the MATLAB process ID.
Refer to your Visual Studio documentation for setting breakpoints in code.
Open MATLAB and type:
yprime(1,1:4)
yprime.c
is opened in the Visual Studio debugger at the first breakpoint.If you select Debug > Continue, MATLAB displays:
ans = 2.0000 8.9685 4.0000 -1.0947