Requirements in a Requirements Table

If I load a requirements table via the slreq.load function, how can the requirement information assocaited with that ReqSet be accessed via commands and NOT through the requirements manager or requirements editor simulink GUIs? I have seen information regarding adding requirements, but there is nothing detailing how to view existing requirements.

Answers (1)

Pat Canny
Pat Canny on 2 Jan 2025
Edited: Pat Canny on 2 Jan 2025
Once you load a Requirement Set, you can use methods from slreq.ReqSet or slreq.Requirement to query or modify the requirement set.
Here's a quick example that retrieves and displays the Id and Descriptions for requirements with type "Requirement" in a Requirement Set loaded from a model containing a Requirements Table:
% Open a Requirements Table example
openExample('shared_vnv/SpecModelForRequirementsTestingExample')
% Load link set and requirement set from model
mdlName = "spec_model_final.slx";
[aLinkSet,aReqSet] = slreq.load(mdlName);
% Find all Requirements in requirements set
reqs = find(aReqSet,"Type","Requirement");
% Create table with Requirement ID and Description
numReqs = length(reqs);
reqDescriptions = cell(numReqs,1);
reqIDs = cell(numReqs,1);
for k = 1:numReqs
reqIDs{k} = reqs(k).Id;
reqDescriptions{k} = reqs(k).getDescriptionAsText;
end
reqIdsAndDescriptions = table(reqIDs,reqDescriptions,'VariableNames',["ID","Description"])
Thanks.
- Pat
Requirements Toolbox Product Manager

5 Comments

What about accessing the associated Preconditions, Actions, Postconditions, etc. for a specific requirement?
You can access those using a few different functions and Requirements Table and Requirement Row properties.
Below is a simple example. I created a simple helper function for demonstration purposes.
This examples just gets data for the first requirement in a Requirements Table. I assume you're looking to find a specific requirement based on some criteria - is that right?
openExample('shared_vnv/SpecModelForRequirementsTestingExample');
spec_model = "spec_model_partial";
open_system(spec_model);
% Get all Requirements Tables in model
reqTables = slreq.modeling.find(spec_model);
% Let's just focus on the first Requirements Table, which defines the
% Autopilot Mode requirements
AP_Mode_Requirements_Table = reqTables(1);
% Get the symbols for the Preconditions, Postconditions, and Actions
AP_Mode_Preconditions = AP_Mode_Requirements_Table.RequirementHeaders.Preconditions
AP_Mode_Postconditions = AP_Mode_Requirements_Table.RequirementHeaders.Postconditions
AP_Mode_Actions = AP_Mode_Requirements_Table.RequirementHeaders.Actions
% Get all requirement rows
AP_Mode_Requirements = getRequirementRows(AP_Mode_Requirements_Table);
% Get Summary, Precondition, Duration, Postcondition, and Action expressions for first requirement
% Use helper function
first_AP_Req = AP_Mode_Requirements(1);
[reqSummary,reqPreconditions,reqDuration,reqPostconditions,reqActions] = getRequirementRowData(first_AP_Req)
% Helper function for getting Summary, Preconditions, Duration,
% Postconditions, and Actions expressions for a Requirement Row
function [reqSummary,reqPreconditions,reqDuration,reqPostconditions,reqActions] = getRequirementRowData(aReqRow)
reqSummary = string(aReqRow.Summary);
reqPreconditions = string(aReqRow.Preconditions);
reqDuration = string(aReqRow.Duration);
reqPostconditions = string(aReqRow.Postconditions);
reqActions = string(aReqRow.Actions);
end
From the information provided, it seems like a reqSet and the requirement tables in a model are spearate data structures. I need to be able to identify a specific requirement row in a requirement table that is associated with a requirement in a reqSet. When I pull the two tables, I would expect them to have the same number of entries, however they do not, which means that the base structrue itself is not sufficient to uniquely identify the correlation, as a result I need a different method to identify the connection between the two data sets.
For example, I want to put the reqSummary from the Requirements Table in the model and put it in a table with the requirement description from the reqSet.
Thanks for clarifying.
We have something we can share with you. We unfortunately can't communicate it via MATLAB Answers as it isn't officially documented. Could you please contact MathWorks Technical Support (category "Help using products") and ask the support team to "escalate" this to the Requirements Toolbox Development Team? You can add a link to this thread in the support request.
Thanks for submitting the support request, @Brennan Fox - working with the team now on a response.

Sign in to comment.

Products

Release

R2024a

Asked:

on 2 Jan 2025

Commented:

on 6 Jan 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!