Main Content

createTextRange

Class: slreq.LinkSet
Namespace: slreq

Create line ranges

Since R2022b

Description

cr = createTextRange(myLinkSet,lines) creates a line range associated with the lines of code, lines, in the MATLAB® or external code file associated with the link set specified by myLinkSet.

example

cr = createTextRange(myLinkSet,blockSID,lines) creates a line range in the MATLAB Function block specified by blockSID.

example

Input Arguments

expand all

Link set, specified as an slreq.LinkSet object.

Start and end line numbers for the line range, specified as a double array of the form [start end] or a scalar double.

Example: [1 4], 1

MATLAB Function block SID, specified as a string scalar or character vector.

Example: "30"

Output Arguments

expand all

Line range, returned as an slreq.TextRange object.

Examples

expand all

This example shows how to create an slreq.TextRange object for a link set.

Load the myAddRequirements requirement set.

rs = slreq.load("myAddRequirements");

Get a handle to the myAdd link set.

myLinkSet = slreq.find(Type="LinkSet",Description="myAdd2");

Create an slreq.TextRange object that corresponds to line numbers 2 in the myAdd function.

cr = createTextRange(myLinkSet,2);

This example shows how to create slreq.TextRange objects in MATLAB Function blocks and link the line ranges to requirements.

Open the myAddModel Simulink® model.

model = "myAddModel";
open_system(model);

Get the SID of the MATLAB Function block.

block = "myAddModel/MATLAB Function";
SID = get_param(block,"SID")
SID = 
'8'

Get a handle to the myAddModel link set.

myLinkSet = slreq.find(Type="LinkSet",Description="myAddModel");

Create an slreq.TextRange object that corresponds to line number 2 in the myAdd MATLAB Function block.

cr = createTextRange(myLinkSet,SID,2);

Load the myAddRequirements requirement set.

rs = slreq.load("myAddRequirements");

Get a handle to the requirement with the summary Add u and v.

req = find(rs,Summary="Add u and v");

Create a link from the slreq.TextRange object to the requirement.

myLink = slreq.createLink(cr,req);

Tips

Version History

Introduced in R2022b