Main Content

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.

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 pairs. You can specify multiple name-value pair 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.

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.

Compile status, specified as one of the values in the table.

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

Whether to search for variables in referenced models, specified as one of the values in the table.

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

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"

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

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)";

Whether to search for variables in masked subsystems, specified as one of the values in the table.

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

Note

You can also set the LookUnderMasks property by using "all" and "none".

Data Types: logical

Whether to follow library links when searching for variables, specified as one of the values in the table.

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.

Note

You can also set the FollowLibraryLinks property by using "on" and "off".

Whether to include variables of inactive variant systems, specified as one of the values in the table.

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

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

expand all

Examples

collapse all

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 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 R2019b

expand all