slreportgen.report.ModelVariable Class
Namespace: slreportgen.report
Superclasses: slreportgen.report.Reporter
Model variable reporter
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.
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
ornext
method of theslreportgen.finder.ModelVariableFinder
object to get theslreportgen.finder.ModelVariableResult
object for the found variable.Call the
getReporter
method of theslreportgen.finder.ModelVariableResult
object to get theslreportgen.report.ModelVariable
object.
You can customize the reporting of a model variable by setting the properties of the
slreportgen.report.ModelVariable
object.
Properties
Variable
— Simulink.VariableUsage
object
Simulink.VariableUsage
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.
ModelBlockPath
— Path of Model block that sets the value of variable
[]
| character vector
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 Configure Instance-Specific Values for Block Parameters in a Referenced Model.
ShowUsedBy
— Whether to include blocks that use this variable
true
(default) | false
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.
ShowWorkspaceInfo
— Whether to include workspace
true
(default) | false
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.
ListFormatter
— List formatter
mlreportgen.dom.UnorderedList
(default) | mlreportgen.dom.OrderedList
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.
FormatPolicy
— Format of variable values
"Auto"
(default) | "Table"
| "Paragraph"
| "Inline Text"
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.
TableReporter
— Table reporter
mlreportgen.report.Basetable
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.
ParagraphFormatter
— Paragraph formatter
mlreportgen.dom.Paragraph
object
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.
TextFormatter
— Text formatter
mlreportgen.dom.Text
object
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.
MaxCols
— Maximum number of table columns to display
32 (default) | positive integer
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.
DepthLimit
— Maximum number of nested levels to report
10 (default) | nonnegative integer
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.
Data Types: double
ObjectLimit
— Maximum number of nested objects to report
200 (default) | positive integer
Maximum number of objects in an object hierarchy to report, specified as a positive integer.
IncludeTitle
— Whether to include title
true
(default) | false
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
— Title of variable to report
[]
(default) | character vector | string scalar | mlreportgen.dom.Text
object | mlreportgen.dom.InternalLink
object | mlreportgen.dom.ExternalLink
object
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
ormlreportgen.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.
ShowDataType
— Whether to show data type of variable in title
false
(default) | true
Whether to show the data type of the variable in the title, specified as true
or false
.
ShowEmptyValues
— Whether to show properties that have empty values
true
(default) | 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.
ShowDefaultValues
— Whether to show properties that use default values
true
(default) | 0
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.
PropertyFilterFcn
— Function or expression to filter properties of a reported model variable
[]
(default) | function handle | string scalar | character vector
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 reportedvariableObject
— The variable being reportedpropertyName
— Name of the property of the variable being reported
Return
true
to filter the specified property from the report, orfalse
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
, andpropertyName
Must set the variable
isFiltered
totrue
to filter the specified property from the report, orfalse
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);
NumericFormat
— Format or precision used to display noninteger numeric values
"%.2f"
(default) | string scalar | character vector | positive integer
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.
TemplateSrc
— Source of template for this reporter
character vector | string scalar | reporter or report | DOM document or document part
Source of the template for this reporter, specified in one of these ways:
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
Document Object Model (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 you
append this reporter. 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.
TemplateName
— Name of template for this reporter
character vector | string scalar
Name of the 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 specified by
the TemplateSrc
property of this reporter.
Data Types: char
| string
LinkTarget
— Hyperlink target for this reporter
[]
(default) | character vector | string scalar | mlreportgen.dom.LinkTarget
object
Hyperlink target for this reporter, specified as a character vector or string scalar
that specifies the link target ID, or an mlreportgen.dom.LinkTarget
object. A character vector or string scalar
value converts to a LinkTarget
object. The link target immediately
precedes the content of this reporter in the output report.
Methods
Public Methods
getVariableName | Get name of variable from model variable reporter |
getVariableValue | Get value of variable from model variable reporter |
slreportgen.report.ModelVariable.createTemplate | Create model variable reporter template |
slreportgen.report.ModelVariable.customizeReporter | Create custom model variable reporter class |
slreportgen.report.ModelVariable.getClassFolder | Get location of model variable reporter class definition file |
copy | Create copy of a Simulink reporter object and make deep copies of certain property values |
getImpl | Get implementation of reporter |
Examples
Customize the Formatting of Model Variables in a Report
Customize the formatting of model variables in a report by iterating through the search results and setting properties of the model variable reporter for each result.
% 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 = "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 Report of Model Variables, Diagrams, and Blocks
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.
% Create a Report rpt = slreportgen.report.Report("MyReport","pdf"); % Load the model model_name = "sf_car"; load_system(model_name); % Create a Chapter for the Variables chapter = mlreportgen.report.Chapter(); chapter.Title = "Model Variable Report for the "+model_name+" model"; % 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
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)