slreportgen.finder.ModelVariableFinder Class
Namespace: slreportgen.finder
Superclasses: mlreportgen.finder.Finder
Finds variables used by a Simulink model
Description
Find variables used by a Simulink® model.
The slreportgen.finder.ModelVariableFinder
class is a handle
class.
Creation
Description
creates a finder that finds variables used in the specified
finder
= slreportgen.finder.ModelVariableFinder(container
)container
, which can be a Simulink model or subsystem. See the Container
property. You can constrain the search by setting the properties of the finder. Use the
methods of the finder to perform the search.
Note
This finder provides these options to get search results:
To return the search results as an array, use the
find
method. Add the results directly to a report or process the results in afor
-loop.To iterate through the results one at a time, use the
hasNext
andnext
methods in awhile
-loop.
Neither option has a performance advantage.
sets properties using name-value pairs. You can specify multiple name-value pair arguments
in any order.finder
= slreportgen.finder.ModelVariableFinder(Name=Value
)
Properties
Container
— Model or subsystem to search
string scalar | character vector | handle
Model or subsystem to search, specified as a string scalar or character vector that contains the path to the model or subsystem, or as a handle to the model or subsystem.
Regexp
— Regular expression matching
false
(default) | true
Regular expression matching, specified as false
or
true
. If Regexp
is false
,
regular expression matching is not enabled. If Regexp
is
true
, regular expression matching is enabled for the values of the
Name
, SourceType
, and Users
properties. For example, this code finds variables that start with
vehicle
.
Run the following command to access the supporting files used in this example.
openExample('rptgenext/SimulinkReportGeneratorFilesExample');
finder = slreportgen.finder.ModelVariableFinder("sf_car"); finder.Regexp = true; finder.Name = "^vehicle";
Note
You can also set the Regexp
property by using
"off"
and "on"
.
See Regular Expressions.
SearchMethod
— Compile status
"compiled"
(default) | "cached"
Compile status, specified as one of the values in the table.
Value | Description |
---|---|
"compiled" | Get up-to-date results by compiling models before the search. (default) |
"cached" | Get results more quickly by using data cached during the previous compilation. |
SearchReferencedModels
— Whether to search referenced models
true
(default) | false
Whether to search for variables in referenced models, specified as one of the values in the table.
Value | Description |
---|---|
true | Search for variables in referenced models. (default) |
false | Do not search for variables in referenced models. |
Note
You can also set the SearchRederencedModels
property by using
"off"
and "on"
.
Name
— Name of variable to search for
[]
(default) | character vector | string scalar
Name of variable to search for, specified as a character vector or string scalar. If
the Regexp
property is set to "on"
, the value of
Name
can be a regular expression. If the Name
property is empty, the finder does not search based on the variable name.
Example: "vehicledata"
Example: "^vehicle"
SourceType
— Source of variable definitions
[]
(default) | "base workspace"
| "model workspace"
| "mask workspace"
| "data dictionary"
Source of variable definitions, specified as one of these values:
"base workspace"
"model workspace"
"mask workspace"
"data dictionary"
If you set SourceType
, the finder returns variables only from the
specified source. If the Regexp
property is set to
"on"
, the value of SourceType
can be a regular
expression. If the SourceType
property is empty, the finder does not
filter the search results by the source.
Example: finder.SourceType = "model workspace"
returns all
variables defined in the model workspace.
Example: finder.SourceType = "(base|mask) workspace"
returns all
variables defined in the base workspace or the mask workspace if the
Regexp
property is set to "On"
.
Example: finder.SourceType = "\w* workspace"
returns all variables
defined in the base, mask, or model workspace if the Regexp
property
is set to "On"
.
Users
— Names of blocks to search for variables
[]
(default) | character vector | string scalar | array of character vectors | string array
Names of blocks to search for variables. Specify one block as a character vector or
string scalar. Specify multiple blocks as an array of character vectors or a string
array. The finder returns variables used by one or more of the specified blocks. If you
do not set the Users
property, the finder searches the entire model
or subsystem. If the Regexp
property is set to
true
, you can set the Users
property to a
regular expression.
For example, to find all variables in MyModel
that are used by
either the Gain1
block or the Gain2
block, you can
specify both blocks in the Users
property.
myFinder.Users = ["myModel/Gain1", "myModel/Gain2"];
Alternatively, you can use a regular expression that matches both block names.
myFinder.Regexp = "on"; myFinder.Users = "Gain(1|2)";
LookUnderMasks
— Whether to search under masks
true
or 1
(default) | false
or 0
Whether to search for variables in masked subsystems, specified as one of the values in the table.
Value | Description |
---|---|
true | Search for variables in masked subsystems. (default) |
false | Do not search for variables in masked subsystems. |
Note
You can also set the LookUnderMasks
property by using
"all"
and "none"
.
Data Types: logical
FollowLibraryLinks
— Whether to follow library links
true
(default) | false
Whether to follow library links when searching for variables, specified as one of the values in the table.
Value | Description |
---|---|
true | Follow links into library blocks. Library links are treated as subsystems. (default) |
false | Do not follow links into library blocks. Library links are treated as blocks. |
Note
You can also set the FollowLibraryLinks
property by using
"on"
and "off"
.
IncludeInactiveVariants
— Whether to include variables of inactive variant systems
false
(default) | true
Whether to include variables of inactive variant systems, specified as one of the values in the table.
Value | Description |
---|---|
false | Do not include variables used by inactive variant systems. (default) |
true | Include variables used by inactive variant systems. Variables in
inactive variants are only found if the Variant activation
time configuration parameter of the containing Variant
Subsystem or Variant Model block is set to
|
Note
You can also set the IncludeInactiveVariants
property by
using "on"
and "off"
.
Properties
— Properties of Simulink.VariableUsage
objects to find
{}
(default) | cell array
Properties of Simulink.VariableUsage
objects to find,
specified as a cell array of name-value pairs. The finder returns only variables whose
associated Simulink.VariableUsage
object has the specified property
values.
Example: finder.Properties = {'SourceType', 'base
workspace'}
Methods
Public Methods
find |
Add
all of the results directly to a report or process the results in a
|
hasNext |
|
next |
|
Examples
Add Model Variables to a Report
Find the variables in a model and add the results directly to a report. Specify that the finder includes variables in masked systems.
% Create a Simulink Report rpt = slreportgen.report.Report("MyReport","pdf"); % Create a Chapter chapter = mlreportgen.report.Chapter(); chapter.Title = "Model Variable Finder Example"; % Load the model model_name = "sf_car"; load_system(model_name) % Create a variable finder and set its properties finder = slreportgen.finder.ModelVariableFinder(model_name); finder.LookUnderMasks = "all"; % Find variables used by the model results = find(finder); % Add the results to the chapter add(chapter,results); % Add chapter to the report add(rpt,chapter); % Close the report and open the viewer close(rpt); rptview(rpt);
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);
Version History
Introduced in R2019bR2022a: New inputs for certain properties
Starting in R2022a, the following properties accept boolean values as inputs:
Regexp
SearchReferencedModels
LookUnderMasks
FollowLibraryLinks
IncludeInactiveVariants
You can also use the legacy inputs for these properties.
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
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)