Main Content

Check for Run-Time Issues by Using the App

Before you generate standalone C/C++ code for your MATLAB® code, it is a best practice to generate a MEX function from your entry-point functions. This step is optional. However, running the MEX function helps you to detect and fix run-time errors that are harder to diagnose in the generated code. It also helps you to verify that the MEX provides the same functionality as the original MATLAB code.

In the MATLAB Coder™ app, to generate and run the MEX function for your MATLAB code, perform the Check for Run-Time Issues step.

  1. Write a function or script that calls your entry-point functions. You can use the same test file (or files) that you use to automatically define input types in the Define Input Types step. Alternatively, you can enter code directly at the app command prompt.

  2. Complete the Select Source Files and Define Input Types steps. On the Define Input Types page, click Next to go to Check for Run-Time Issues step.

  3. Specify the test file. In the previous step, if you automatically generated the input types, the app populates the dialog box with that test file. Instead of a test file, you can enter code that calls your entry-point functions. However, it is a best practice to provide a test file.

  4. Click Check for Issues. The app generates a MEX function from your MATLAB function. It runs the test that you specified, substituting calls to your MATLAB entry-point functions with calls to the generated MEX function. The app reports MEX generation or build errors on the Errors tab. The app reports MEX run-time errors on the Test Output tab.

  5. If the app reports errors, to edit the MATLAB code, click View errors.

  6. After you fix issues, to rerun the test, click Check for Issues.

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

Collect MATLAB Line Execution Counts

When the app runs the MEX function, it counts executions of the MEX code that corresponds to a line of MATLAB code. If the app does not detect issues, you can view these line execution counts. The 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. See Collect and View Line Execution Counts for Your MATLAB Code.

Reset Line Execution Counts

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.

Disable JIT Compilation for Parallel Loops

By default, to speed up generation of the MEX function, the app tries to use just-in-time (JIT) compilation. JIT compilation is incompatible with certain code generation features and options such as custom code and use of the OpenMP library. If the app cannot use JIT compilation, it generates a C/C++ MEX function instead. If your code uses parfor and the Enable OpenMP library if possible setting is Yes, the app uses JIT compilation and treats the parfor-loops as for-loops. If you want the Check for Run-Time Issues step to run for-loops in parallel, disable JIT compilation:

  1. On the Check for Run-Time Issues page, click Settings.

  2. On the All Settings tab, set Use JIT compilation in Check for Run-Time Issues to No.

Related Topics