Requirements Traceability for MATLAB Code Lines

Link MATLAB Code Lines to Requirements in a Requirement Set

Create Links by Using Context Menu Shortcuts

To create requirements traceability links from MATLAB® code lines to requirements in the Requirements Editor, use the Requirements context menu in the MATLAB Editor.

  1. Load the requirement set that contains the requirement that you want to link to.

  2. Navigate to the Requirements Editor and select the requirement.

  3. In the MATLAB Editor, select the line or lines of code that you want to link.

  4. Right-click your selection.

  5. From the context menu, select Requirements > Link to Selection in Requirements Browser.

Simulink® Requirements™ creates a traceability link from the MATLAB code lines to the selected requirement in the Requirements Editor. Navigate from your requirements to the MATLAB code lines by using the navigation links available from the Links pane in the Requirements View of the Requirements Editor.

Create Links Through the Outgoing Links Dialog Box

Create requirements traceability links between MATLAB code lines and requirements in requirement sets by using the Outgoing Links dialog box.

  1. Load the requirement set that contains the requirement that you want to link to.

  2. Navigate to the Requirements Editor and select the requirement.

  3. In the MATLAB Editor, select the line or lines of code that you want to link to the requirement.

  4. Right-click your selection.

  5. From the context menu, select Requirements > Open Outgoing Links dialog.

  6. In the Outgoing Links dialog box, click New.

  7. From the Document type drop-down list, select Requirement Set.

  8. Populate the Document field and the requirement Description by clicking Use current.

  9. Click OK.

Navigate from your requirements to MATLAB code lines by using the navigation links available from the Links pane in the Requirements View of the Requirements Editor.

Note

When you link code lines from a MATLAB-based Simulink test to a requirement, the code lines that you select determine the type of link and the test to which it is added. SeeTest Models Using MATLAB-Based Simulink Tests (Simulink Test) .

Link MATLAB Code Lines to Requirements Information in External Documents

Create Link by Using Context Menu Shortcuts

To create requirements traceability links from MATLAB code lines to selections in Microsoft® Word, Microsoft Excel®, or IBM® Rational® DOORS® documents, use shortcuts in the Requirements Traceability context menu.

  1. In your requirements document, select the target requirement for the traceability link that you want to create.

  2. In the MATLAB Editor, select the line or lines of code that you want to link to the requirement.

  3. In the MATLAB Editor, right-click your selection.

  4. From the context menu, select Requirements. Depending on the type of your requirements document, select one of these options:

    • Link to Selection in Word

    • Link to Selection in Excel

    • Link to Selection in DOORS

    The software creates a traceability link from the selected MATLAB code range to the selection in the requirements document. If you have bidirectional linking enabled, the software also inserts a navigation object for the selection in the requirements document. The navigation object links to the selected MATLAB code range.

Create and Edit Links Through the Outgoing Links Dialog Box

You can create, edit, and delete traceability links through the Outgoing Links dialog box. To open the Outgoing Links dialog box:

  • In the MATLAB Editor, select the line or lines of code that you want to link to requirements.

  • Right-click your selection.

  • From the context menu, select Requirements > Open Outgoing Links dialog.

See Outgoing Links Editor.

Enable or Disable Traceability Links Highlighting for MATLAB Code

Review traceability in your MATLAB code by highlighting code lines that have requirements links.

Enable Traceability Highlighting of MATLAB Code

To highlight traceability links in your MATLAB code, do one of the following:

  • In the View tab, in the Display section, select Highlight Traceability.

  • In the MATLAB Editor, right-click in a line of code with a traceability link. From the context menu, select Requirements > Enable Traceability Highlighting.

Disable Traceability Highlighting of MATLAB Code

To turn off highlighting of traceability links in your MATLAB code, do one of the following:

  • In the View tab, in the Display section, clear Highlight Traceability.

  • In the MATLAB Editor, right-click in a line of code with a traceability link. From the context menu, select Requirements > Disable Traceability Highlighting.

Remove Traceability Links from MATLAB Code Lines

Delete Links to Requirements from MATLAB Code Lines

To remove requirements traceability links from a line or lines of MATLAB code:

  1. In the MATLAB Editor, right-click within a range of code that has requirements traceability links.

  2. From the context menu, select Requirements > Delete All Links.

    All links to requirements from this MATLAB code range are deleted. Links to this MATLAB code range from external requirements documents are not deleted.

Delete Link Targets in MATLAB Code Lines

If you have links to MATLAB code ranges from external requirements documents, you can delete the targets for these links from your MATLAB code.

To remove requirements traceability targets from a line or lines of MATLAB code:

  1. Delete outgoing links as described in Delete Links to Requirements from MATLAB Code Lines.

  2. In the MATLAB Editor, right-click within a previously linked range of code.

  3. From the context menu, select Requirements > Discard Named Range.

    When you discard a named range, links to that MATLAB code range from external documents no longer work. Discarding named ranges does not delete navigation objects in external requirements documents.

Traceability for MATLAB Code Lines

Traceability Link Targets

You can create MATLAB code traceability links for:

  • Lines of MATLAB code in a standalone file.

  • Lines of MATLAB code inside a MATLAB Function block.

You can create links from a line or lines of MATLAB code to:

  • Selections in Simulink Requirements.

  • Objects in Simulink models.

  • Targets in Microsoft Word or Microsoft Excel documents.

  • Targets in IBM Rational DOORS databases.

  • Targets in text, HTML, or PDF documents.

  • HTTP URLs.

Bidirectional linking is supported for targets in MATLAB, Simulink, Microsoft Word, Microsoft Excel, and IBM Rational DOORS. Bidirectional linking creates links to and from the selected link destination. To enable bidirectional linking, in the Requirements Settings dialog box, under the Selection Linking tab, select Modify destination for bidirectional linking. For more information, see Selection Linking Tab.

You can also create links to MATLAB code lines from any external application that supports HTTP navigation.

Traceability Links in Code Generation Reports

Embedded Coder® embeds requirements traceability links for MATLAB files that are saved externally from the Simulink model and referenced from MATLAB Function blocks in Simulink. In the code generation report, click the hyperlink to navigate to the corresponding requirement in the Requirements Editor. See Generate Code for Models with Requirements Links.

Storage of Traceability Links

In a standalone MATLAB file, you can create, navigate, and delete traceability links for lines of code without changing the MATLAB file. The Requirements Management Interface (RMI) stores requirements traceability data for a MATLAB file in a .req file with the same name and location as the MATLAB file.

If you want to create traceability links for lines of code in a MATLAB Function block, set the parent model to store requirements data externally. For a new model, see Requirements Link Storage. For an existing model, see Move Internally Stored Requirements Links to External Storage. When you create traceability links for code inside a MATLAB Function block, the RMI stores them in a .req file for the parent model. The .req file for the model contains requirements traceability data for linked model objects and for linked code in MATLAB Function blocks in the model.

Limitations of MATLAB Code Traceability

The software does not support traceability links for overlapping regions of MATLAB code. If one linked range of code completely overlaps another smaller region of code, the link for the larger range takes precedence over the link for the smaller range. To avoid complications from overlapping linked ranges, when you create traceability links for MATLAB code lines, choose ranges of code that do not overlap.

You can cut or copy a selection of code that has traceability links. When you paste that selection, the software attempts to recreate the corresponding traceability links. Depending on location and code formatting, you might need to recreate the traceability links manually.

If you select code that has traceability links and drag that code to a new location, you might need to recreate traceability links for the code in the new location.

Requirements linked to individual MATLAB code lines inside a MATLAB Function block appear in HTML requirements traceability reports but do not appear the Simulink Report Generator™ Web View. See Create and Use a Web View (Simulink Report Generator).

Requirements traceability is not supported for MATLAB Live Editor.

Related Topics