In MATLAB 6.5 (R13), you can use the MATLAB Add-In for Visual Studio to set up a project for debugging your MEX file.
If you do not have the add-in setup, see the solutions attached at the bottom of this page.
Now, to debug your MEX file:
1. Start Visual C++.
2. From the menu bar, select File / New.
3. Select a Visual MATLAB project type.
4. Select C MEX as Application Type. Press Finish.
From there you can add your files to the project.
Then finally to compile and debug:
a. To compile, first save your code
b. Select Build->Build MEX_Project.dll
Your .dll should now be ready to run in MATLAB.
To debug your .dll
a. Save your code
b. Place breakpoints in your code
c. Select Build->Debug->Go
You will be prompted to enter the executable to be used for debugging, since you are debugging
a .dll. You should enter $MATLAB\bin\matlab.exe, where $MATLAB is the directory in which
MATLAB is installed. Click OK, and a debugging session will start.
d. Once inside the MATLAB session, type the name of your MEX file (with possibly the required arguments). This should bring you into the MSVC debugger. Please refer to the MSVC manual for more information about debugging.
Best Answer