Main Content

slreportgen.report.ModelVariable class

Package: slreportgen.report
Superclasses: slreportgen.report.Reporter

Model variable reporter

Since R2019b

Description

Reporter for a Simulink® model variable.

Note

To use an slreportgen.report.ModelVariable reporter in a report, you must create the report using the slreportgen.report.Report class or subclass.

The slreportgen.report.ModelVariable class is a handle class.

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

You do not create an slreportgen.report.ModelVariable object explicitly. To get the slreportgen.report.ModelVariable object for a found model variable:

  • Use the find or next method of the slreportgen.finder.ModelVariableFinder object to get the slreportgen.finder.ModelVariableResult object for the found variable.

  • Call the getReporter method of the slreportgen.finder.ModelVariableResult object to get the slreportgen.report.ModelVariable object.

You can customize the reporting of a model variable by setting the properties of the slreportgen.report.ModelVariable object.

Properties

expand all

The Simulink.VariableUsage object that corresponds to the variable to report on. The object contains the name of the variable, the source of the variable, and the blocks that use the variable. This property is read-only.

Path of the Model block that sets the variable value, specified as a character vector.

Suppose that a referenced model uses a model argument to set a block parameter value. If a model has multiple instances of the referenced model, the model variable finder returns multiple instances of the variable that is associated with the model argument. The ModelBlockPath property uniquely identifies the instance of the variable by providing the path to the model block that set its value. If a variable is not associated with a model argument in a referenced model, the ModelBockPath is empty. For more information about referenced models and instance-specific parameters, see Parameterize Instances of a Reusable Referenced Model.

Whether to include a list of blocks that use this variable, specified as true or false. If the FormatPolicy property has a value of "Inline Text", the list of blocks is not included in the report, regardless of the value of the ShowUsedBy property.

If the report includes reported content for a block in the Used By list, clicking the hyperlink for the block takes you to the content. See Generate Report of Model Variables, Diagrams, and Blocks.

Whether to include the workspace that the variable is resolved in, specified as true or false. If the FormatPolicy property has a value of "Inline Text", the workspace is not included in the report, regardless of the value of the ShowWorkspaceInfo property.

List formatter that formats the list of blocks that use the variable, specified as an mlreportgen.dom.UnorderedList object or an mlreportgen.dom.OrderedList object. The default value of this property is an object of mlreportgen.dom.UnorderedList. To customize how the list is formatted, modify the list object properties or replace the list object with a customized list object that does not contain list items.

Format of the variable values, specified as one of these strings or character vectors:

  • "Auto" — Formats the variable values as a table or a paragraph, depending on the data type of the value.

    Data types formatted as a table include:

    • Cell array

    • Logical array

    • Numeric array

    • MATLAB® table

    • Simulink object

    • Stateflow® object

    • Graphics object

    • MATLAB structure or structure array

    • MATLAB object or object array

    Data types formatted as a paragraph include:

    • Cell vector

    • Logical scalar or vector

    • Numeric scalar or vector

    • Character or character array

    • String

    • MATLAB structure vector

    • MATLAB object vector

  • "Table" — Formats the variable values in a table. Variables that by default appear as paragraphs are formatted instead as table entries. Variables that are hierarchically structured objects, such as a MATLAB structures, MATLAB objects, Simulink objects, Stateflow objects, or graphics objects, can have properties that are themselves objects. In that case, the hierarchy is flattened and the property value is displayed as a hyperlink to a table of the properties of that object. The object property table also has a hyperlink back to the original table.

  • "Paragraph" — Format the variable values as a paragraph. Variables that by default are formatted as tables are flattened and formatted as a paragraph.

  • "Inline Text" — Formats the variable in line with the surrounding text.

Table reporter used to format the value of the variable, specified as an mlreportgen.report.BaseTable object. The default value of this property is a BaseTable object with the TableStyleName property set to the ModelVariableTable style, which is defined in the default template for a ModelVariable reporter.

To customize the appearance of the table, modify the properties of the default table reporter or replace it with a customized table reporter. If you add content to the Title property of the default or customized table reporter, the content appears in front of the table title in the generated report.

Paragraph formatter to format the value of a model variable, specified as an mlreportgen.dom.Paragraph object. The default value of this property is a BaseTable object with the TableStyleName property set to the ModelVariableParagraph style, which is defined in the default template for a ModelVariable reporter.

To customize the appearance of the paragraph, modify the properties of the mlreportgen.dom.Paragraph object or replace the object with a customized mlreportgen.dom.Paragraph object. If you add content to the default or replacement paragraph object, the content appears in front of the variable content in the generated report.

Text formatter to format the name and value of the model variable when the text is in line with the surrounding text, specified as an mlreportgen.dom.Text object. To customize the appearance of the text, modify the properties of the default mlreportgen.dom.Text object or replace the object with a customized mlreportgen.dom.Text object. If you add content to the default or replacement text object, the content appears in front of the variable content in the generated report.

Maximum number of table columns to display, specified as a positive integer. For array variables reported using a table, if the number of columns is greater than the value of the MaxCols property, the table is sliced vertically. Slicing divides the table into multiple tables.

Maximum number of levels to report for a variable that is a structured object or an array of structured objects, specified as a nonnegative integer. Levels less than or equal to the value of DepthLimit are flattened into a sequence of interlinked tables (see the FormatPolicy property). Levels greater than the depth limit are not reported. If you set the DepthLimit property to 0, structured objects are not expanded.

Maximum number of objects in an object hierarchy to report, specified as a positive integer.

Whether to include a title, specified as true or false. The title contains the variable name and optionally, the data type. If IncludeTitle is true, the title is included. By default, the title includes only the name of the variable. To include the data type of the variable, set the ShowDataType property to true.

Title of variable to report, specified as a character vector, string scalar, mlreportgen.dom.Text object, mlreportgen.dom.InternalLink object, or mlreportgen.dom.ExternalLink object.

If the FormatPolicy property is set to "Inline Text" and the Title property is set to:

  • A DOM object, the formatting specified by the DOM object is ignored

  • An mlreportgen.dom.InternalLink or mlreportgen.dom.ExternalLink object, the link text is used for the title, but the title is not a link

In both cases, to format the title, use the TextFormatter property of this ModelVariable reporter.

If you do not specify the Title property, the title is the variable name.

Whether to show the data type of the variable in the title, specified as true or false.

Whether to show properties that have empty values, specified as a true or false. The ShowEmptyValues property applies only to MATLAB object, Simulink object, and Stateflow object variables.

Whether to show properties that use the default value, specified as true or false. The ShowDefaultValues property applies only to MATLAB object, Simulink object, and Stateflow object variables.

Function or expression to filter the properties of a reported model variable from a report. Specify a function as a function handle. Specify an expression as a string scalar or character vector. This property applies only to a variable that contains an object. If you do not provide PropertyFilterFcn, all properties of the model variable are included in the report.

If you provide a function handle, the associated function must:

  • Take these arguments:

    • variableName — Name of the variable being reported

    • variableObject — The variable being reported

    • propertyName — Name of the property of the variable being reported

  • Return true to filter the specified property from the report, or false to include the property in the report.

For example, this code prevents the display of the Description and Complexity properties of a Simulink.Parameter object.

import slreportgen.finder.*
import slreportgen.report.*

rpt = slreportgen.report.Report('modelvarrpt','pdf');

model_name = load_system('sldemo_mdlref_datamngt');


finder = slreportgen.finder.ModelVariableFinder(model_name);

while hasNext(finder)
    result = next(finder);
    varRptr = getReporter(result);
    varRptr.PropertyFilterFcn = @varPropertyFilter;
    add(rpt,varRptr);
end

close(rpt);

close_system(model_name);
rptview(rpt);

function tf = varPropertyFilter(~, variableObject,propertyName)
if isa(variableObject, 'Simulink.Parameter')
    tf = (propertyName == "Description") ||  ...
        (propertyName == "Complexity");
else
    tf = false;
end
end

If you provide a string scalar or a character vector, it must contain an expression. The expression:

  • Can use the variables variableName, variableObject, and propertyName

  • Must set the variable isFiltered to true to filter the specified property from the report, or false to include the property in the report

For example, this code filters the CoderInfo property of a Simulink.Parameter object from the report.

import slreportgen.finder.*
import slreportgen.report.*

rpt = slreportgen.report.Report('modelvarrpt','pdf');

model_name = load_system('sldemo_mdlref_datamngt');


finder = slreportgen.finder.ModelVariableFinder(model_name);

while hasNext(finder)
    result = next(finder);
    varRptr = getReporter(result);
    
    varRptr.PropertyFilterFcn = "isFiltered = " + ...
        "isa(variableObject, 'Simulink.Parameter') && " + ...
        "propertyName == 'CoderInfo';";
    add(rpt,varRptr);
end

close(rpt);

close_system(model_name);
rptview(rpt);

Format or precision used to display noninteger numeric values.

Specify the format as a string scalar or a character vector. See the formatSpec argument on the sprintf reference page.

Specify the precision as a positive integer. See the precision argument on the num2str reference page.

Example: "%.2f" displays double values with two digits to the right of the decimal place.

Example: 2 displays a maximum number of two significant digits.

Source of the template for this reporter, specified as one of these options:

  • Character vector or string scalar that specifies the path of the file that contains the template for this reporter

  • Reporter or report whose template is used for this reporter or whose template library contains the template for this reporter

  • DOM document or document part whose template is used for this reporter or whose template library contains the template for this reporter

The specified template must be the same type as the report to which this reporter is appended. For example, for a Microsoft® Word report, TemplateSrc must be a Word reporter template. If the TemplateSrc property is empty, this reporter uses the default reporter template for the output type of the report.

Name of template for this reporter, specified as a character vector or string scalar. The template for this reporter must be in the template library of the template source (TemplateSrc) for this reporter.

Hyperlink target for this reporter, specified as a character vector or string scalar that specifies the link target ID or as an mlreportgen.dom.LinkTarget object. A character vector or string scalar value is converted to a LinkTarget object. The link target immediately precedes the content of this reporter in the output report.

Methods

expand all

Examples

collapse all

Use the properties of an slreportgen.report.ModelVariable object to customize the formatting of a variable.

Run the following command to access the supporting files used in this example.

openExample('rptgenext/SimulinkReportGeneratorFilesExample');
% Create a Report
rpt = slreportgen.report.Report("MyReport","pdf");

% Create a Chapter
chapter = mlreportgen.report.Chapter();
chapter.Title = "Model Variable Reporter Example";

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

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

while hasNext(finder)
    result = next(finder);
    
    % Get the ModelVariable reporter for the result
    % Customize the formatting of numbers
    reporter = getReporter(result);
    reporter.NumericFormat = "%.4f";
    
    % Add the reporter to the chapter
    add(chapter,reporter);
end
% Add chapter to the report
add(rpt,chapter);

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

Generate a report that includes:

  • A chapter for the model variables

  • A chapter for each model diagram, with a section for the blocks in the diagram

Each block name in the Used By list for a model variable is a hyperlink to the corresponding content reported for the block.

Run the following command to access the supporting files used in this example.

openExample('rptgenext/SimulinkReportGeneratorFilesExample');
% Create a Report
rpt = slreportgen.report.Report("MyReport","pdf");

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

% Create a Chapter for the Variables
chapter = mlreportgen.report.Chapter();
chapter.Title = sprintf("Model Variable Report for the %s model",model_name);

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

% Report on the variables
while hasNext(finder)
    result = next(finder);
    reporter = getReporter(result);
    add(chapter,reporter);
end
add(rpt,chapter);

% Add diagrams to the report
finder = slreportgen.finder.DiagramFinder(model_name);
while hasNext(finder)
    result = next(finder);
    ch = mlreportgen.report.Chapter(result.Name);
    add(ch, result);
    % Add a section for the blocks in the diagram
    sect = mlreportgen.report.Section("Title","Blocks");
    blFinder = slreportgen.finder.BlockFinder(result.Object);
    while hasNext(blFinder)
        blockresult = next(blFinder);
        add(sect,blockresult);
    end
    add(ch,sect);
    add(rpt, ch);
end

% Close and view the report
close(rpt);
rptview(rpt);

Version History

Introduced in R2019b