MATLAB Examples

Trace Generated Code to Blocks

Navigate and trace between generated code and its source model for validation.

Contents

Open Example Model

Open the example rtwdemo_hyperlinks.

model='rtwdemo_hyperlinks';
open_system(model)

Code to Model Navigation

Navigate from the code to the model.

  1. Open the Code Generation > Report pane of the Configuration Parameters dialog box.
  2. Verify the following parameters are selected: Create code generation report, Open report automatically and Model-to-code.
  3. In the model editor window, press Ctrl+B to generate code. When code generation is complete, the software displays a code generation report with hyperlinks.
  4. In the generated report, click the rtwdemo_hyperlinks.c link to see the code with embedded hyperlinks.
  5. Click links in the code to trace generated code segments to the highlighted elements in the model. For example, if you click the hyperlink <Root>/Sum, the Sum block in the model is highlighted.

Model to Code Navigation

Navigate from the model to the code.

  1. Open the Code Generation > Report pane of the Configuration Parameters dialog box.
  2. Verify the following parameters are selected: Create code generation report, Open report automatically and Model-to-code.
  3. In the model editor window, press Ctrl+B to generate code. When code generation is complete, the software displays a code generation report with hyperlinks.
  4. In the model window, right-click any block and select Code Generation > Navigate to Code. The software highlights the generated code for this block in the code generation report.
  5. Inspect the highlighted lines in the code generation report. The total number of highlighted lines is displayed next to each source file name in the left pane of the report. Use the Previous and Next buttons to navigate through the highlighted lines.

Note: Model-to-code navigation also works for Stateflow objects and MATLAB functions.

Note: The report displays a diagnostic message if there is no code to highlight for the selected block (for example, if you select a virtual block).

Traceability Report

Generate and inspect the Traceability Report.

  1. Open the Code Generation > Report of the Configuration Parameters dialog box.
  2. Verify the following parameters are selected: Create code generation report, Open report automatically and
  3. Find the traceability report parameters using keyword GenerateTraceReport. Verify all the listed parameters are selected.
  4. In the model editor window, press Ctrl+B to generate code. When code generation is complete, the software displays a code generation report with hyperlinks.
  5. To see a report of the untraceable (not in the generated code) and traceable blocks in your model, on the left pane of the generated report click Traceability Report.
  6. In the Traceability Report, inspect the Eliminated / Virtual Blocks and Traceable Blocks lists. For example, the Scope block is an untraceable block. It is listed under Eliminated / Virtual Blocks because the code generator does not create code for this block.