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.

Code Generation in MATLAB

Several Computer Vision Toolbox™ functions have been enabled to generate C/C++ code. To use code generation with computer vision functions, follow these steps:

  • Write your Computer Vision Toolbox function or application as you would normally, using functions from the Computer Vision Toolbox.

  • Add the %#codegen compiler directive to your MATLAB® code.

  • Open the MATLAB Coder™ app, create a project, and add your file to the project. Once in MATLAB Coder, you can check the readiness of your code for code generation. For example, your code may contain functions that are not enabled for code generation. Make any modifications required for code generation.

  • Generate code by clicking Generate in the Generate Code dialog box. You can choose to build a MEX file, a C/C++ shared library, a C/C++ dynamic library, or a C/C++ executable.

    Even if you addressed all readiness issues identified by MATLAB Coder, you might still encounter build issues. The readiness check only looks at function dependencies. When you try to generate code, MATLAB Coder might discover coding patterns that are not supported for code generation. View the error report and modify your MATLAB code until you get a successful build.

For more information about code generation, see the MATLAB Coder documentation and the Introduction to Code Generation with Feature Matching and Registration example.


To generate code from MATLAB code that contains Computer Vision Toolbox functionality, you must have the MATLAB Coder software.

When working with generated code, note the following: