Simulink.findVars

Variables found in models and blocks

Syntax

  • [variables] = Simulink.findVars(context) example
  • [variables] = Simulink.findVars(context,Name,Value) example
  • [variables] = Simulink.findVars (context,variablefilter,Name,Value) example

Description

example

[variables] = Simulink.findVars(context) returns as a vector Simulink.VariableUsage objects found in the blocks and models specified by context, including subsystems and referenced models. Returns an empty vector if none are found.

example

[variables] = Simulink.findVars(context,Name,Value) uses additional options specified by one or more Name,Value pair arguments.

example

[variables] = Simulink.findVars (context,variablefilter,Name,Value) returns results only for variables specified by variablefilter.

Examples

expand all

Variables in Use in a Model

Find variables used by MyModel.

[variables] = Simulink.findVars('MyModel');

Specific Variable in Use in a Model

Find all uses of the base workspace variable k by MyModel using the cached results.

[variables] = Simulink.findVars('MyModel','Name','k',
'SearchMethod','cached','SourceType','base workspace');

Regular Expression Matching

Find any usage of a variable whose name matches the regular expression ^trans.

[variables] = Simulink.findVars('MyModel','Regexp','on',
'Name','^trans');

Variables Common to Two Models

Given two models, discover which variables are used by the first, the second, or both.

[model1Vars] = Simulink.findVars('model1');
[model2Vars] = Simulink.findVars('model2');
[commonVars] = intersect(model1vars,model2Vars);

Variables Not Used in a Model

Return variables in the model workspace that are not used by MyModel.

unusedVars = Simulink.findVars('MyModel','FindUsedVars',false,
'SourceType','model workspace');

Specific Variable Not Used in a Model

Determine if the base workspace variable k is not used by MyModel.

varObj = Simulink.VariableUsage('k','base workspace');
unusedVar = Simulink.findVars('MyModel',varObj,
'FindUsedVars',false);

Variables Used by a Block

Return the variables that are used by the Gain1 block in MyModel.

[variables] = Simulink.findVars('MyModel',
'Users','MyModel/Gain1');

Variables Used in a Model Reference Hierarchy

Find variables used within the model reference hierarchy in MyNestedModel.

[variables] = Simulink.findVars('MyNestedModel','SearchReferencedModels','on');

Input Arguments

expand all

context — Models and blocks to searchstring | cell array

Models and blocks to search, specified in one of the following ways:

  • The name of a model ('MyModel')

  • The name or path of a block or masked block ('MyModel/Gain')

  • A cell array of model or block names

Example: [variables] = Simulink.findVars('MyModel')

Data Types: char | cell

variablefilter — Filter of variables to findSimulink.VariableUsage object | array of Simulink.VariableUsage objects

Filter of variables to find, specified as a Simulink.VariableUsage object or an array of Simulink.VariableUsage objects.

Example:

vars = [Simulink.VariableUsage('k','base workspace')
			Simulink.VariableUsage('myParam','base workspace')];
variablefilter = Simulink.findVars('MyModel',vars)

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'FindUsedVars','true','Regexp','on','Name','^mod' specifies for the search to return variables in use having names that match the pattern ^mod.

'FindUsedVars' — Find variables that are used or not usedtrue (default) | logical scalar | double scalar | string

Option to find variables that are explicitly used or not used, specified as the comma-separated pair consisting of FindUsedVars and a Boolean.

Example: 'FindUsedVars',false

'RegExp' — Enable regular expression matching'off' (default) | logical scalar | double scalar | string

Option to enable regular expression matching, specified as the comma-separated pair consisting of RegExp' and on. Only input arguments with string values can be matched.

Example: 'RegExp','on'

'SearchMethod' — Compile status'compiled' (default) | 'cached'

Compile status, specified as the comma-separated pair consisting of SearchMethod and one of these values:

  • 'compiled' — Return up-to-date results by compiling every model in the search context before search.

  • 'cached' — Return quicker results by using results cached during the previous compile.

Example: 'SearchMethod','compiled'

'SearchReferencedModels' — Enable search within referenced models'off' (default) | logical scalar | double scalar | string

Option to enable search within referenced models, specified as the comma-separated pair consisting of SearchReferencedModels and on.

Example: 'SearchReferencedModels','on'

'Name' — Name of a variable to search forstring

Name of a variable to search for, specified as the comma-separated pair consisting of Name and a string.

Example: 'Name','trans'

'SourceType' — Workspace or source containing the variablestring

Workspace or source containing the variable, specified as the comma-separated pair of SourceType and one of the following options:

  • 'base workspace'

  • 'model workspace'

  • 'mask workspace'

  • 'data dictionary'

Example: 'SourceType','base workspace'

'Users' — Names of blocks to search for variablesstring

Names of blocks to search for variables, specified as the comma-separated pair consisting of Users and a string.

Example: 'Users','MyModel/Gain1'

Data Types: char

Limitations

Simulink.findVars does not work with the following constructs:

  • MATLAB® code in scripts and initialization and callback functions

  • Libraries and blocks within libraries

  • MATLAB Function blocks, except for input arguments

  • Calls directly to MATLAB from the Stateflow® action language

  • S-functions that use data type variables registered using ssRegisterDataType.

    To make the variables searchable, use ssRegisterTypeFromNamedObject instead.

  • Variables of enumerated classes

  • Variables used by inactive variant subsystems

  • Variables referenced by machine-parented data in Stateflow

Was this topic helpful?