slreportgen.finder.ModelVariableFinder Class
Namespace: slreportgen.finder
Superclasses: mlreportgen.finder.Finder
Find variables used by Simulink model
Description
Use objects of the class slreportgen.finder.ModelVariableFinder to find the
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
findmethod. 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
hasNextandnextmethods in awhile-loop.
Neither option has a performance advantage.
sets properties using name-value arguments. You can specify multiple name-value arguments in any order.finder = slreportgen.finder.ModelVariableFinder(Name=Value)
Properties
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.
Attributes:
GetAccess | public |
SetAccess | public |
Whether to match regular expressions, specified as "on" or
"off", or as numeric or logical 1 (true) or 0
(false). A value of "on" is equivalent to
true, and "off" is equivalent to
false. Thus, you can use the value of this property as a logical value.
The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState..
"on" — enables regular expression matching for the values of the
Name,SourceType, andUsersproperties."off" — disables regular expression matching.
For more information on regular expressions, see Regular Expressions.
Attributes:
GetAccess | public |
SetAccess | public |
Compiled status of the models, specified as one of these values.
| Value | Description |
|---|---|
"compiled" | Get up-to-date results by compiling models before the search. |
"cached" | Get results more quickly by using data cached during the previous compilation. |
Whether to search for variables in referenced models, specified as one of these values:
| 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".
Attributes:
GetAccess | public |
SetAccess | public |
Data Types: logical
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"
Attributes:
GetAccess | public |
SetAccess | public |
Data Types: char | string
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".
Attributes:
GetAccess | public |
SetAccess | public |
Data Types: char | string
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)";
Attributes:
GetAccess | public |
SetAccess | public |
Data Types: char | string
Whether to search in masked subsystems, specified as one of these values.
| Value | Description |
|---|---|
true | Search for variables in masked subsystems. (default) |
false | Do not search for variables in masked subsystems. |
Data Types: logical
Whether to follow library links, specified as one of these values:
| 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. |
Attributes:
GetAccess | public |
SetAccess | public |
Data Types: logical
Whether to include variables of inactive variant systems, specified as one of these values:
| 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".
Attributes:
GetAccess | public |
SetAccess | public |
Data Types: logical
Properties of Simulink.VariableUsage objects to find,
specified as a cell array of name-value arguments. The finder returns only variables whose
associated Simulink.VariableUsage object has the specified property
values.
Example: finder.Properties = {"SourceType", "base
workspace"}
Attributes:
GetAccess | public |
SetAccess | public |
Data Types: cell
Methods
find |
Add
all of the results directly to a report or process the results in a
|
hasNext |
|
next |
|
Examples
Find the variables in a model and add the results directly to a report.
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.
finder = slreportgen.finder.ModelVariableFinder(model_name);
Specify that the finder includes variables in masked systems.
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);
Find the variables in a model that start with vehicle and add the results to a report.
Load the model.
model_name = "sf_car";
load_system(model_name)Create a variable finder.
finder = slreportgen.finder.ModelVariableFinder(model_name);
Enable regular expression matching.
finder.Regexp = true;
Use the regular expression ^vehicle to constrain the search to results that start with vehicle.
finder.Name = "^vehicle";Find the matching variables used by the model.
results = find(finder)
results =
ModelVariableResult with properties:
Object: [1×1 Simulink.VariableUsage]
Name: "vehicledata"
Source: "sf_car"
SourceType: "model workspace"
Users: "sf_car/Vehicle"
ModelBlockPath: []
Tag: []
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);
For each result, get the ModelVariable reporter for the result, customize the formatting of numbers, and add the reporter to the chapter.
while hasNext(finder) result = next(finder); reporter = getReporter(result); reporter.NumericFormat = "%.4f"; add(chapter,reporter); end
Add the chapter to the report.
add(rpt,chapter);
Close the report and open the viewer.
close(rpt); rptview(rpt);
Version History
Introduced in R2019bStarting in R2022a, the following properties accept boolean values as inputs:
RegexpSearchReferencedModelsLookUnderMasksFollowLibraryLinksIncludeInactiveVariants
You can also use the legacy inputs for these properties.
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.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- 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)