MATLAB: How to merge two Simulink Requirement sets to create a general requirements coverage and report

mergerequirementsetSimulink Requirements

I have a device which consists of two modules: A and B. These modules are rather independent, so they are designed and developed separately. There is a requirements list (in plain text) for the entire device.
I wrote a script which makes two Requirement Sets (SLREQX) for A and B separately. So each has its own "ReqSet" and achieve 100% requirements coverage. To achieve this, the requirements are linked to each model – and Simulink saves these links to files named "model_name.slmx".
But after these two models are finished, I want to generate the general requirements report for the whole device with both models together. Therefore, how do I merge these Requirements sets (to obtain a general Requirement set for the entire device) and re-allocate links in SLMX files from particular "ReqSets" to the general "ReqSet"?

Best Answer

The solution to this depends on the MATLAB version you are using. For MATLAB R2019a, please refer to example code attached '*testReqSetMerge.m*'. This file includes a function '*testReqSetMerge*' that combines two Requirement sets and updates the links. At the top of the function inside the file, there is a commented example on how you can use the function with two sample models, '*vdp*' and '*my_sfcar*'.
In short, the script takes the following arguments:
  • The name for the new combined ReqSet.
  • A cell array of ReqSet objects or character vector names for all linked ReqSets.
  • A cell array of LinkSet objects or character vector names of the linked models.
  • TRUE or FALSE for whether to delete original links (optional argument).
In MATLAB R2020a, the function '*link.setDestination()*' allows to implement this in an easier way: