Requirements in a Requirements Table
Show older comments
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)
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
Brennan
on 3 Jan 2025
Pat Canny
on 3 Jan 2025
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
Brennan
on 3 Jan 2025
Pat Canny
on 4 Jan 2025
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.
Pat Canny
on 6 Jan 2025
Categories
Find more on Model and Validate Requirements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!