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.
To see the Project API functions for each operation in this example, view the example code.
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:
Select the Code Generation template from the start page, and create the
Generate controller code for the
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 the top-level harness
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
Scope block in the model and observe the simulation output.
To open the scope and observe simulation, in the Simulink window, double-click the
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.