Main Content

Set Up a MATLAB Coder Project

  1. To open the app, on the MATLAB® Toolstrip Apps tab, under Code Generation, click the MATLAB Coder™ app icon.

  2. Create a project or open an existing project. See Create a Project and Open an Existing Project.

  3. If the app detects code generation readiness issues in your entry-point functions, address these issues.

  4. Define the properties of the entry-point function input types. See Define or Edit Input Parameter Type by Using the App.

  5. Check for run-time issues. Provide code or a test file that the app can use to test your code. The app generates a MEX function. It runs your test code or test file, replacing calls to your MATLAB function with calls to the MEX function. This step is optional. However, it is a best practice to perform this step. You can detect and fix run-time errors that are harder to diagnose in the generated C code.

  6. Configure the build settings. Select the build type, language, and production hardware. Optionally, modify other build settings. See Configure Build Settings.

    You can now generate code.

Create a Project

On the Select Source Files page, specify the MATLAB files from which you want to generate code. An entry-point function is a function that you call from MATLAB. Do not add files that have spaces in their names.

The app creates a project that has the name of the first entry-point function.

To add additional entry-point functions, click Add Entry-Point Function, and then type or select the name of the entry-point function. To delete an entry-point function, click Cancel icon. To change an entry-point function, click Edit icon.

If you have a Fixed-Point Designer™ license, you can set the Numeric Conversion option to indicate that you want to generate fixed-point or single-precision C/C++ code:

  • To generate code without conversion to fixed-point or single-precision types, select None (default).

  • To convert floating-point MATLAB code to fixed-point C/C++ code, select Convert to fixed point.

  • To convert double-precision MATLAB code to single-precision C/C++ code, select Convert to single precision.

Open an Existing Project

  1. On the app toolbar, click Action menu icon and select Open existing project.

  2. Type or select the project.

The app closes other open projects.

When you open a project from a different release, the MATLAB Coder app updates the project file so that the format is compatible with the release that you are using if necessary. Before the app updates the project file, it creates a backup file with the name project_name.prj.bak. For example, the backup file name for myproject.prj is myproject.prj.bak. If the backup file exists, the app inserts an integer between the prj and bak extensions to make the file name unique. For example, if myproject.prj.bak exists, the app creates the backup file myproject.prj.2.bak.

If the project file is from a release before R2015a, the app also displays a message about the project file update and backup. To use the project in a release before R2015a, use the backup project file instead of the updated project file.

To use a backup project file, remove the extensions that follow the prj extension. For example, rename myproject.prj.2.bak to myproject.prj. If you use the backup project file in the release that created it, the project is the same as the original project. If you use the backup project file in a different release than the one that created it, you can possibly lose some information. For example, if you open a project file in a release that does not recognize a setting in the file, that setting is lost. For best results, open the backup project file in the release in which you created it.

Reopen a Project in a Different App

  1. On the app toolbar, click Action menu icon and select Reopen project as.

  2. Select the app in which you want to open the project.

Project settings persist when you reuse a project in a different app.

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

If the project is a Fixed-Point Converter project, and you have a Fixed-Point Designer license, the project opens in the Fixed-Point Converter app.