帮助中心帮助中心
本页采用了机器翻译。点击此处可查看英文原文。
创建行范围
自 R2022b 起
lr = slreq.createTextRange(fileName,lines)
lr = slreq.createTextRange(fileName,blockSID,lines)
示例
lr = slreq.createTextRange(fileName,lines) 在 fileName 指定的文件中创建与代码行 lines 关联的行范围。
lr
fileName
lines
lr = slreq.createTextRange(fileName,blockSID,lines) 在 blockSID 指定的 MATLAB Function模块中创建一个行范围。
blockSID
全部折叠
此示例显示如何创建 slreq.TextRange 对象并将其链接到需求。
slreq.TextRange
创建一个与myAdd函数中的行号 1 和 2 对应的slreq.TextRange对象。
myAdd
lineRange = slreq.createTextRange("myAdd.m",[1 2]);
在 MATLAB® 编辑器中查看 slreq.TextRange 对象。
show(lineRange);
加载myAddRequirements需求集。
myAddRequirements
rs = slreq.load("myAddRequirements");
通过摘要 Add u and v 获取需求句柄。
Add u and v
req = find(rs,Summary="Add u and v");
创建从 slreq.TextRange 对象到需求的链接。
myLink = slreq.createLink(lineRange,req);
此示例显示如何在 MATLAB Function 模块中创建slreq.TextRange 对象并将对象链接到需求。
打开 myAddModel Simulink®模型。
myAddModel
model = "myAddModel"; open_system(model);
获取 MATLAB Function 模块的 SID。
block = "myAddModel/MATLAB Function"; SID = get_param(block,"SID");
创建一个与 myAdd MATLAB Function 模块中的第 2 行号对应的 slreq.TextRange 对象。
tr = slreq.createTextRange(model,SID,2);
myLink = slreq.createLink(tr,req);
包含代码行的文件的名称,指定为字符串标量或字符向量。
示例: "myAdd.m"
"myAdd.m"
double
行范围的起始和结束行号,指定为 [start end] 形式的双精度数组或双精度标量。
[start end]
示例: [1 4], 1
[1 4]
1
MATLAB Function 模块 SID,指定为字符串标量或字符向量。
示例: "30"
"30"
行范围,以 slreq.TextRange 对象形式返回。
您还可以使用 slreq.LinkSet 的 createTextRange 方法来创建行范围。
slreq.LinkSet
createTextRange
在 R2022b 中推出
slreq.TextRange | slreq.getTextRange | createTextRange
slreq.getTextRange
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office