Main Content

Generate Code and Simulate Models in a Project

This example shows how to use the code generation template for a new Project. The code generation project template for Project includes multiple models. The project template also provides utilities (.m scripts) that help you generate controller code and run simulations of the harness model.

Create a Project

Create a new Project from the code generation project template.

To create this project from the Simulink® start page, in the Command Window, type:

simulink

Select the Code Generation template from the start page, and create the exampleCodeGen project.

Generate Code

Generate controller code for the feedback_control.slx model.

To generate controller code, select the Project Shortcuts tab and select the Generate Controller Code shortcut.

This shortcut runs the generate_controller_code.m script in the utilities folder of the project. The script builds the feedback_control.slx model in the controller folder of the project.

Simulate Models

Simulate the top-level harness feedback_harness.slx model.

To open the harness model for simulation, select the Project Shortcuts tab and select the Feedback Harness shortcut. This shortcut opens the feedback_harness.slx model in the harnesses folder of the project.

To simulate the model, click Run.

Observe Simulation Output

Open the Scope block in the model and observe the simulation output.

To open the scope and observe simulation, in the Simulink window, double-click the Scope block.

Use the Dependency Analyzer View

To view file dependencies, use the Dependency Analyzer view of the project.

From the Dependency Analyzer view, you can:

  • Observe file dependencies.

  • Hover over the dependency arrows to examine the dependency type.

  • Double-click on a file or a model to open it.

More Information

Related Examples