Main Content

Collect and View Line Execution Counts for Your MATLAB Code

When you perform the Check for Run-Time Issues step in the MATLAB® Coder™ app, you must provide a test that calls your entry-point functions with representative data. The Check for Run-Time Issues step generates a MEX function from your MATLAB functions and runs the test, replacing calls to the MATLAB functions with calls to the MEX function. When running the MEX function, the app counts executions of the MEX code that corresponds to a line of MATLAB code. These line execution counts help you to see how well your test exercises your MATLAB code. You can identify dead code and sections of code that require further testing.

To see the line execution counts, after the Check for Run-Time Issues step finishes the test, click View MATLAB line execution counts.

App window, showing the Check for Run-Time Issues pane

In the app editor, the app displays a color coded bar to the left of your MATLAB code.

App editor window, showing the Code Analyzer

This table describes the color coding.


One of the following situations:

  • The entry-point function executes multiple times and the code executes more than one time.

  • The entry-point function executes one time and the code executes one time.

Different shades of green indicate different ranges of line execution counts. The darkest shade of green indicates the highest range.

OrangeThe entry-point function executes multiple times, but the code executes one time.
RedCode does not execute.

When you place your pointer over the bar, the color highlighting extends over the code. For each section of code, the app displays the number of times that the section executes.

App editor window, showing color coding representing line execution counts in the Code Analyzer

Collection of line execution counts is on by default. Turn it off only after you have verified that you have adequate test file coverage. Turning off line execution counts can speed up the Check for Run-Time Issues step. To turn off collection of line executions counts, in the Check for Run-Time Issues dialog box, clear the Collect MATLAB line execution counts check box.

If you check for run-time issues multiple times, the line execution counts accumulate. To set the counts to zero, click Reset line execution counts.

The MATLAB Coder app is not supported in MATLAB Online™.

Related Examples

More About