Main Content

copy

Class: slreq.Requirement
Namespace: slreq

Copy and paste requirement

Since R2020b

Syntax

tf = copy(req1,location,req2)

Description

tf = copy(req1,location,req2) copies requirement req1 and pastes it under, before, or after requirement req2 depending on the location specified by location. The function returns 1 if the copy and paste is executed.

Note

If you copy a requirement and paste it within the same requirement set, the copied requirement retains the same custom attribute values as the original. If the requirement is pasted into a different requirement set, the copied requirement does not retain the custom attribute values.

Input Arguments

expand all

Requirement to copy, specified as an slreq.Requirement object.

Paste location, specified as 'under', 'before', or 'after'.

Requirement, specified as an slreq.Requirement object.

Output Arguments

expand all

Paste success status, returned as a 1 or 0 of data type logical.

Examples

expand all

This example shows how to copy a requirement and paste it under, before, or after another requirement.

Load the crs_req_func_spec requirement file, which describes a cruise control system, and assign it to a variable. Find two requirements by index. The first requirement will be copied and pasted in relation to the second requirement.

rs = slreq.load('crs_req_func_spec');
req1 = find(rs,'Type','Requirement','Index','1');
req2 = find(rs,'Type','Requirement','Index','2');

Paste Under a Requirement

Copy and paste the first requirement, req1, under the second requirement, req2. The first requirement becomes the last child requirement of req2, which you can verify by finding children of req2 and comparing the summary of the last child and req1.

tf = copy(req1,'under',req2);
childReqs = children(req2);
lastChild = childReqs(numel(childReqs));
lastChild.Summary
ans = 
'Driver Switch Request Handling'
req1.Summary
ans = 
'Driver Switch Request Handling'

Paste Before a Requirement

Copy and paste the first requirement, req1, before the second requirement, req2. Confirm that the requirement was pasted before req2 by checking the index and Summary. The old index of req2 was 2. The index of the pasted requirement should be 2 and the index of req2 should be 3.

tf = copy(req1,'before',req2);
pastedReq = find(rs,'Type','Requirement','Index','2');
pastedReq.Summary
ans = 
'Driver Switch Request Handling'
req2.Index
ans = 
'3'

Paste After a Requirement

Copy and paste the first requirement, req1, after the second requirement, req2. Confirm that the requirement was pasted after req2 by checking the index. The index of req2 is 3 and should not change, which means the index of the pasted requirement should be 4.

tf = copy(req1,'after',req2);
pastedReq2 = find(rs,'Type','Requirement','Index','4');
pastedReq2.Summary
ans = 
'Driver Switch Request Handling'
req2.Index
ans = 
'3'

Version History

Introduced in R2020b