Main Content

本页采用了机器翻译。点击此处可查看英文原文。

getVariableID

类: slreportgen.finder.ModelVariableResult
命名空间: slreportgen.finder

获取模型变量的唯一 ID

语法

varID = getVariableID(variableResult)

说明

varID = getVariableID(variableResult) 返回一个唯一标识模型变量搜索结果所代表的变量的字符串。该 ID 是变量的 slreportgen.report.ModelVariable 报告器的 LinkTarget 属性的默认值。因此,您可以使用该 ID 为变量生成指向报告内容的链接。

输入参数

全部展开

使用 slreportgen.finder.ModelVariableFinder 对象的 findnext 方法进行搜索的结果。

输出参量

全部展开

模型变量的唯一 ID,以字符串标量的形式返回。

示例

全部展开

您可以使用 getVariableID 方法返回的变量 ID 为该变量创建指向报告内容的链接。此示例生成 sf_car 模型使用的变量的报告。报告开头的变量列表提供了变量报告内容的链接。

% Create a Report
rpt = slreportgen.report.Report("MyReport","pdf");

% Load the model
model_name = "sf_car";
load_system(model_name);

% Create a Chapter
chapter = mlreportgen.report.Chapter();
chapter.Title = "Variables Used in the "+model_name+" model";

% Find the variables in the model
finder = slreportgen.finder.ModelVariableFinder(model_name);
results = find(finder);

% Create a list of the variables with links to the reported variable content
ul = mlreportgen.dom.OrderedList;
for r = results
    varname = r.Name;
    %get ID that is used for the link target for this variable
    varid = getVariableID(r);
    link = mlreportgen.dom.InternalLink(varid,varname);
    li = mlreportgen.dom.ListItem();
    append(li,link);
    append(ul,li);
end
add(chapter,ul);

% Add reporters for the variables to report
for r = results
    % Get the ModelVariable reporter for the result
    % Customize the formatting of numbers
    reporter = getReporter(r);
    reporter.NumericFormat = "%.4f";
    
    % Add the reporter to the chapter
    add(chapter,reporter);
    
end
add(rpt,chapter);

% Close the report and open the viewer
close(rpt);
rptview(rpt);

版本历史记录

在 R2019b 中推出