Main Content

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.

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

finder = slreportgen.finder.ModelVariableFinder(container) creates a finder that finds variables used in the specified 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 a for-loop.

  • To iterate through the results one at a time, use the hasNext and next methods in a while-loop.

Neither option has a performance advantage.

example

finder = slreportgen.finder.ModelVariableFinder(Name=Value) sets properties using name-value arguments. You can specify multiple name-value arguments in any order.

Properties

expand all

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, and Users properties.

  • "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.

ValueDescription
"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:

ValueDescription
trueSearch for variables in referenced models. (default)
falseDo 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.

ValueDescription
trueSearch for variables in masked subsystems. (default)
falseDo not search for variables in masked subsystems.

Data Types: logical

Whether to follow library links, specified as one of these values:

ValueDescription
trueFollow links into library blocks. Library links are treated as subsystems. (default)
falseDo 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:

ValueDescription
falseDo 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 code compile or update diagram analyze all choices. To include variables in Model blocks that are inactive systems, the SearchReferencedModels property of this finder must also be set to true.

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

expand all

Examples

collapse all

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 R2019b

expand all