This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Debug MATLAB Function Called by C Engine

When creating MATLAB® functions for use in engine applications, it is good practice to run the functions in MATLAB before calling them through the engine library functions.

After you integrate a MATLAB function into an engine application, you can use the dbstop and other MATLAB debugging commands to debug the function invoked by the engine application. You might need to add code to the application to pause processing so that you can enter a debug command, unless you attach the application to an existing MATLAB session.

Debug Engine Application on Windows

Assume that you have an engine application that calls a MATLAB function myfcn on Windows®. Add the following statement to your engine code before the call to myfcn. This code waits for user input.

fgetc(stdin);

Start the engine application. The application opens a MATLAB desktop and a Windows console application of MATLAB. At the desktop command prompt, type the following command. Make sure the function is on your MATLAB path.

dbstop("myfcn")

In the console window, press Enter. MATLAB enters debug mode; type debug commands in the desktop command window.

Debug Engine Application Attached to Existing MATLAB Session

For information about using an existing MATLAB session, see Attach to Existing MATLAB Sessions. To debug function myfcn called by an engine application, first start MATLAB as an Automation server with one of the following commands.

  • From the system prompt:

    matlab.exe -automation
  • From the MATLAB command prompt:

    state = enableservice('AutomationServer',true);

At the MATLAB command prompt, type:

dbstop("myfcn")

Start the engine application. MATLAB enters debug mode; type debug commands in the MATLAB command window.