Package: slreportgen.report
Model variable reporter
Reporter for a Simulink® model variable.
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.
HandleCompatible | true |
For information on class attributes, see Class Attributes (MATLAB).
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.
Variable
— Simulink.VariableUsage
objectSimulink.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 vectorPath 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 (Simulink).
ShowUsedBy
— Whether to include blocks that use this variabletrue
(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 formattermlreportgen.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. 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. 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 formattermlreportgen.dom.Paragraph
objectParagraph formatter to format the value of a model variable, specified as an mlreportgen.dom.Paragraph
object. 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 formattermlreportgen.dom.Text
objectText 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 displayMaximum 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 reportMaximum 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.
ObjectLimit
— Maximum number of nested objects to reportMaximum number of objects in an object hierarchy to report, specified as a positive integer.
IncludeTitle
— Whether to include titletrue
(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
.
ShowDataType
— Whether to show data type of variable in titlefalse
(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 valuestrue
(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 valuestrue
(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 vectorFunction 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);
NumericFormat
— Format or precision used to display noninteger numeric values"%.2f"
(default) | string scalar | character vector | positive integerFormat 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 reporterSource 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
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.
TemplateName
— Name of template for this reporterName of the template for this reporter, specified as a character vector or string
scalar. The template for this reporter is in the template library of the template source
(TemplateSrc
) for this reporter.
LinkTarget
— Hyperlink target for this reporter[]
(default) | character vector | string scalar | mlreportgen.dom.LinkTarget
objectHyperlink target for this reporter, specified as a string or character array that
specifies the link target ID, or an mlreportgen.dom.LinkTarget
object. A string or character array value is
converted to a LinkTarget
object. The link target object immediately
precedes the content of this reporter in the output report.
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 |
getImpl | Get implementation of reporter |
Use the properties of a
slreportgen.report.ModelVariable
object to customize the formatting of a
variable.
% 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 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 = 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);
Simulink.VariableUsage
| slreportgen.finder.ModelVariableFinder
| slreportgen.finder.ModelVariableResult
| slreportgen.report.BusObject
아래 MATLAB 명령에 해당하는 링크를 클릭하셨습니다.
이 명령을 MATLAB 명령 창에 입력해 실행하십시오. 웹 브라우저에서는 MATLAB 명령을 지원하지 않습니다.
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: .
Select web siteYou 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.