Call the C/C ++ program in MATLAB

Source: Internet
Author: User

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.





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.