Main Content

getVariableID

Class: slreportgen.finder.ModelVariableResult
Namespace: slreportgen.finder

Get unique ID of model variable

Since R2019b

Syntax

varID = getVariableID(variableResult)

Description

varID = getVariableID(variableResult) returns a string that uniquely identifies the variable represented by the model variable search result. This ID is the default value of the LinkTarget property of the slreportgen.report.ModelVariable reporter for the variable. Therefore, you can use the ID to generate a link to the reported content for the variable.

Input Arguments

expand all

Result of a search using the find or next method of an slreportgen.finder.ModelVariableFinder object.

Output Arguments

expand all

Unique ID for the model variable, returned as a string scalar.

Examples

expand all

You can use the variable ID returned by the getVariableID method to create a link to the reported content for the variable. This example generates a report of the variables used by the sf_car model. The list of variables at the beginning of the report provides links to the reported content for the variables.

% 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);

Version History

Introduced in R2019b