Main Content

slreq.createTextRange

Create line ranges

    Description

    example

    lr = slreq.createTextRange(fileName,lines) creates a line range associated with the lines of code, lines, in the file specified by fileName.

    example

    lr = slreq.createTextRange(fileName,blockSID,lines) creates a line range in the MATLAB Function block specified by blockSID.

    Examples

    collapse all

    This example shows how to create an slreq.TextRange object and link it to a requirement.

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

    tr = slreq.createTextRange("myAdd.m",[1 2]);

    View the slreq.TextRange object in the MATLAB® Editor.

    show(tr);

    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(tr,req);

    This example shows how to create slreq.TextRange objects in MATLAB Function blocks and link the objects 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");

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

    tr = slreq.createTextRange(model,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(tr,req);

    Input Arguments

    collapse all

    Name of the file containing the lines of code, specified as a string scalar or character vector.

    Example: "myAdd.m","vdp.slx"

    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

    collapse all

    Line range, returned as an slreq.TextRange object.

    Tips

    Version History

    Introduced in R2022b