Main Content

Generate Code for Models with Requirements Links

To specify that generated code of an ERT target include requirements:

  1. Open the CodeRequirementsLinks example model. At the command line, type openExample('CodeRequirementsLinks.slx').

  2. On the Modeling tab, click Model Settings.

  3. In the Configuration Parameters dialog box, on the left pane, select the Code Generation pane.

    Set the parameter System target file to ert.tlc, or an ERT-based system target file.

  4. Under Code Generation, select Comments.

  5. In the Custom comments section on the right, select the Requirements in block comments check box.

  6. Under Code Generation, select Report.

  7. On the Report pane, select:

    • Create code generation report

    • Open report automatically

  8. Press Ctrl+B to build the model.

  9. In the code generation report, open CodeRequirementsLinks.c.

  10. Scroll to the code for the Pulse Generator block, clock. The comments for the code associated with that block include a hyperlink to the requirement linked to that block.

    Section of C code for the clock block showing comments that identify the clock block and the requirement associated with the block.

  11. Click the link Clock period shall be consistent with chirp tolerance to open the HTML requirements document to the associated requirement.


    When you click a requirements link in the code comments, the software opens the application for the requirements document, except if the requirements document is a DOORS® module. To view a DOORS requirement, start the DOORS software and log in before clicking the hyperlink in the code comments.

You can also include requirements comments in generated HDL code. For more information, see Requirement Comments and Hyperlinks (HDL Coder).

How Requirements Information Is Included in Generated Code

After you simulate your model and verify its performance against the requirements, you can generate code from the model for an embedded real-time application. The Embedded Coder® software generates code for Embedded Real-Time (ERT) targets.

If the model has any links to requirements, the Embedded Coder software inserts information about the requirements links into the code comments.

For example, if a block has a requirement link, the software generates code for that block. In the code comments for that block, the software inserts:

  • Requirement description

  • Hyperlink to the requirements document that contains the linked requirement associated with that block


  • You must have a license for Embedded Coder to generate code for an embedded real-time application.

  • If you use an external SLMX file to store your requirement links, to avoid stale comments in generated code, before code generation, you must save any change in your requirement links. For information on how to save, see Save Requirements Links in External Storage.

  • Generated code does not include links from comments in MATLAB function blocks, Stateflow® MATLAB® functions, or external MATLAB function files.

Comments for the generated code include requirements descriptions and hyperlinks to the requirements documents in the following locations.

Model Object with RequirementLocation of Code Comments with Requirements Links


In the main header file, <model>.h

Nonvirtual subsystem

At the call site for the subsystem

Virtual subsystem

At the call site of the closest nonvirtual parent subsystem. If a virtual subsystem does not have a nonvirtual parent, requirement descriptions appear in the main header file for the model, <model>.h.

Nonsubsystem block

In the generated code for the block

MATLAB code line in MATLAB Function block

In the generated code for the MATLAB code line(s)

Related Topics