MATLAB Coder - Generate C code or MEX function from MATLAB code - MATLAB (original) (raw)

Generate C code or MEX function from MATLAB code

Description

The MATLAB Coder app generates C and C++ code from MATLAB® code as standalone static libraries, dynamically linked libraries, or executables. The generated code can be embedded in applications outside the MATLAB environment. The MATLAB Coder™ app also generates C/C++ MATLAB executable (MEX) functions designed for MATLAB acceleration. The MATLAB Coder app is integrated into the MATLAB desktop and is available in MATLAB Online™.

The user interface includes:

Using the app, you can:

When the app creates a project, the app enables Embedded Coder features if the Embedded Coder product is installed. When Embedded Coder features are enabled, code generation requires an Embedded Coder license. To disable Embedded Coder features, open the MEX Code Generation Settings or Standalone Code Generation Settings dialog box. On the Advanced pane, clear theUse Embedded Coder features check box.

MATLAB Coder app

Open the MATLAB Coder App

Programmatic Use

Version History

Introduced in R2015a

expand all

The MATLAB Coder app has a new look and feel and is integrated into the MATLAB desktop.

You can use the MATLAB Coder app in MATLAB Online.

The MATLAB Coder app saves code generation project files with a.coderprj extension, instead of with a.prj extension. If you open a MATLAB Coder project file created before R2025a in the new app, the app saves a copy of the PRJ file to a CODERPRJ file. If you save changes to your project, the changes are saved to the CODERPRJ file, not the PRJ file. In some cases, the app is unable to migrate parameters that are specific to a hardware support package from the PRJ file to the CODERPRJ file. If you use a hardware support package, verify that the configuration parameters are correct before generating code.

To check for issues in the generated MEX file, use the Run Generated MEX button in the MATLAB Coder toolstrip. To perform verification using MEX, you must provide aMATLAB Coder script that exercises your entry points (also known as a_test bench_). In previous releases, you verified the generated code by using the Check for Issues step in theMATLAB Coder app.

After you verify the generated code by using Run Generated MEX, you can view line execution counts and other execution profile data by using the MATLAB Profiler. See Profile MEX Functions by Using MATLAB Profiler. Before R2025a, line execution counts were available in the MATLAB Coder app after completing the Check for Issues step.

The MATLAB Coder app no longer supports numeric conversion. Perform numeric conversion at the command line by using the codegen command.

The Search paths parameter is not available when you generate code by using the MATLAB Coder app. To add additional folders to the search path, generate code at the command line by using the codegen command with the-I option.