| Contents | Index |
You can use MathWorks code generation technology to generate standalone C or C++ source code for embedded systems:
By developing MATLAB algorithms with Code Generation from MATLAB and then generating C/C++ code with the MATLAB Coder and Embedded Coder products
By developing Simulink models and Stateflow charts and then generating C/C++ code with the Simulink Coder and Embedded Coder products
By integrating MATLAB code into Simulink models, using Code Generation from MATLAB and the Simulink MATLAB Function block, and then generating C/C++ code with the Simulink Coder and Embedded Coder products
The following figure shows the design and deployment environment options. Although not shown in the figure, other products that support code generation, such as Stateflow software, are available.

The following table summarizes how to generate C or C++ code for each of the approaches and identifies where you can find more information.
| If you develop algorithms using... | You generate code by... | For more information, see... |
|---|---|---|
| Code generation from MATLAB | Using MATLAB Coder projects Entering the function codegen in the MATLAB Command Window | Workflow Overview in the MATLAB Coder documentation. |
| Simulink and Stateflow | Configuring and initiating code generation for your model or subsystem with the Simulink Configuration Parameters dialog. | Simulink and Stateflow Model in the Simulink Coder documentation |
| Code generation from MATLAB and Simulink | Including MATLAB code in Simulink models or subsystems by using the MATLAB Function block. To use this block, you can do one of the following:
| Code Generation from MATLAB documentation MATLAB Function block in the Simulink documentation |
To use MATLAB code and Simulink models for a Model-Based Design project:
Start by using MATLAB to develop an algorithm for research and early development.
Later want to integrate the algorithm into a graphical model for system deployment and verification.
Benefits of this approach include:
Richer system simulation environment
Ability to verify the MATLAB code
Simulink Coder and Embedded Coder C/C++ code generation for the model and MATLAB code
If you are familiar with C language constructs and want to learn about how to map commonly used C constructs to code generated from model design patterns that include Simulink blocks, Stateflow charts, and MATLAB functions, see Patterns for C Code in the Embedded Coder documentation.
![]() | Target Environments and Applications | MATLAB Tutorials | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |