Documentation

Use Traceability in MATLAB Function Blocks

Extent of Traceability in MATLAB Function Blocks

Like other Simulink® blocks, MATLAB Function blocks support bidirectional traceability, but extend navigation to lines of source code. That is, you can navigate between a line of generated code and its corresponding line of source code. In other Simulink blocks, you can navigate between a line of generated code and its corresponding object.

In addition, you can select to include the source code as comments in the generated code. When you select MATLAB source code as comments parameter, the MATLAB® source code appears immediately after the associated traceability tag. For more information, see How to Include MATLAB Code as Comments in the Generated Code.

For information about how traceability works in Simulink blocks, see What Is Code Tracing? (Embedded Coder).

Traceability Requirements

To enable traceability comments in your code, you must have a license for Embedded Coder® software. These comments appear only in code that you generate for an Embedded Real-Time (ERT) target.

Note

Traceability is not supported for MATLAB files that you call from a MATLAB Function block.

Tutorial: Using Traceability in a MATLAB Function Block

This example shows how to trace between source code and generated code in a MATLAB Function block in the eml_fire model. Follow these steps:

  1. Type eml_fire at the MATLAB prompt.

  2. In the Simulink model window, select Simulation > Model Configuration Parameters.

  3. In the Code Generation pane, go to the Target selection section and enter ert.tlc for the system target file. Then click Apply.Traceability comments appear hyperlinked in generated code only for embedded real-time (ert) targets.

  4. In the Code Generation > Report pane, select the Create code generation report (Simulink Coder) parameter, if not already selected.

    This action automatically selects the Open report automatically (Simulink Coder), Code-to-model (Simulink Coder), and Model-to-code (Simulink Coder) parameters.

  5. Verify that Code-to-model and Model-to-code parameters are enabled.

  6. In the Code Generation > Comments pane, select the MATLAB source code as comments (Simulink Coder) and Stateflow object comments (Simulink Coder) parameters. These parameters control different parts of the traceability comment. See Location of Comments in Generated Code for more information.

  7. Go to the Code Generation > Interface pane. In the Software environment section, select the continuous time parameter. Then click Apply. Because this example model contains a block with a continuous sample time, you must perform this step before generating code.

  8. In the model window, press Ctrl+B.

    This action generates source code and header files for the eml_fire model that contains the flame block. After the code generation process is complete, the code generation report appears automatically.

  9. Click the eml_fire.c hyperlink in the report.

  10. Scroll down through the code to see the traceability comments, which appear as links inside /*...*/ brackets, as in this example.

  11. Click the <S2>:1:19 hyperlink in this traceability comment:

    /* '<S2>:1:19' */

    Line 19 of the function in the source code appears highlighted in the MATLAB Function Block Editor.

  12. You can trace a line in a MATLAB function to lines of generated code. For example, right-click on line 21 of your function and select Code Generation > Navigate to Code from the context menu.

    The code location for line 21 appears highlighted in eml_fire.c.

  13. You can trace a line of generated code to a line of source code in a MATLAB function using the line number hyperlinks in the generated code.

Related Examples

More About

Was this topic helpful?