This article is transferred from: herohbc
Syntax errors can be provided by the compiler during compilation in the compilation of the mexfunction, but logical errors can be found only after debugging. This article describes how to debug the Mex function in visual studio2008. This is the last article in this series.
We use the example in the previous article, that is, using the function provided by opencv to calculate the determinant of a square matrix, to demonstrate how to debug it.
1. Create a new project in vs2008, see the article "call C/C ++ program in MATLAB (3)", the URL is: http://hi.baidu.com/herohbc/item/2bc1b62348be8857c28d5952
2. Set a breakpoint in the mexfunction and compile the project in debug mode, as shown in.
3. Open MATLAB and set current folder to the debug folder under the directory where the current project is located. For example, the current folder of this program is F: \ temp \ introduction to algorithms \ det_opencv \ debug.
4. in Visual Studio 2008, choose tools> attach to process...in the dialog box that appears, and then click attach, as shown in.
4. Enter the command in the Command window of MATLAB:
> A = rand (4, 4 );
> D = det_opencv ();
At this time, the program runs to the breakpoint of det_opencv, as shown in. In this way, we can perform debugging step by step. You can check whether the variable value is correct at any time during the debugging process.