Link MAT File Variables to Requirements Using Traceability Matrix
This example shows how you can create link between a MAT file variable and a requirement in a requirements set. You use traceability matrix where you generate a matrix between MAT file variable and a requirement and then create a link between them. A traceability matrix displays links between items in Model-Based Design artifacts. For more information on traceability matrices, see Track Requirement Links with a Traceability Matrix.
Open Project
Open the Requirements Definition for a Cruise Control Model project. Load the crs_req_func_spec
requirement set.
openProject("CruiseRequirementsExample"); slreq.load("crs_req_func_spec");
The project contains:
Requirement sets for functional and test requirements, located in the
documents
folderThe Simulink ® model and link set files, located in the
models
folderMATLAB unit tests, located in the
tests
folderData dictionary and MAT file located in the
data
folderScripts to automate project analysis, located in the
scripts
folder
Generate Traceability Matrix
1. Open the Traceability Matrix window. Create an options structure for the traceability matrix.
opts = slreq.getTraceabilityMatrixOptions;
2. Set the topArtifacts
and leftArtifacts
properties of opts
as crs_data.mat
and crs_req_func_spec.slreqx,
respectively.
opts.topArtifacts = "crs_data.mat"; opts.leftArtifacts = "crs_req_func_spec.slreqx";
3. Generate the traceability matrix with the artifacts specified by opts
.
slreq.generateTraceabilityMatrix(opts);
A traceability matrix is generated with the crs_req_func_spec.slreqx
requirement set on the left and the crs_data.mat
MAT file on the top. For more information, see slreq.generateTraceabilityMatrix
.
Alternatively, you can create a traceability matrix from the Traceability Matrix window. To create a matrix with the MAT file and the requirement set, click the Add button to open the Select Artifacts dialog box. In the Select Artifacts dialog, select crs_req_func_spec.slreqx
from the Left list and crs_data.mat
from the Top list. Click Generate Matrix.
Create Link between MAT File Variable and Requirement Programmatically
1. Get the object for the link source. Create a structure containing properties of the MAT file variable TWAIT
.
src.id = "TWAIT"; src.artifact = "crs_data.mat"; src.domain = "linktype_rmi_mat";
2. Get the object for the link destination. In this case, create a link for a requirement with the summary as Switch precedence
. Find the requirement related to the link.
dest = slreq.find(Type='Requirement',Summary='Switch precedence');
3. Create the link between the MAT file variable TWAIT
and the requirement with the summary as Switch precedence
.
newLink = slreq.createLink(src,dest);
4. Click Update on the Traceability Matrix window.
In the Requirements Editor, the link appears in the Details pane, under Links.
Create Link between MAT File Variable and Requirement from Traceability Matrix Window
Create a link between variable Kp
from crs_data.mat
file to the requirement with index 1.3.1
in by using the Traceability Matrix window.
1. Open Traceability Matrix window.
2. In the Traceability Matrix window, click on the cell at the intersection of Kp
from the crs_data.mat
MAT file and the requirement with index 1.3.1
.
3. Click Create Link or Create in the information box that appears.
4. The Create Link dialog box shows the link source and destination. Click Create.
The arrow icon in a cell indicates that there is a link between the item in that row and column.
5. Click on the link in the cell in the Traceability Matrix window to open the Links view of Requirements Editor.
6. Click Show Requirements in the Requirements Editor. Observe that the Links pane shows the default link type set to Related to
when you create links from a traceability matrix between requirements and MAT file variables.
See Also
Create Links from Test Files, Test Suites, and Test Cases | Create Links