Documentation

Simulink.VariableUsage class

Package: Simulink

Get information about workspace variables and blocks that use them

Tip

Only a Simulink.VariableUsage constructor can set any property value in a Simulink.VariableUsage object. The properties are otherwise read only.

Description

Create a Simulink.VariableUsage object to get the attributes of a workspace variable and determine the blocks that use the variable.

You can also use the Simulink.findVars function to create Simulink.VariableUsage objects that describe the variables and, optionally, enumerated data types that are used by a model.

Construction

vars = Simulink.VariableUsage(VarNames,SourceName) creates an array of Simulink.VariableUsage objects to describe the variables VarNames. The constructor sets the Name property of each object to one of the variable names specified by VarNames, and sets the Source property of all the objects to the source specified by SourceName.

You can specify VarNames with variables that are not used in any loaded models.

Input Arguments

collapse all

VarNames — Names of target variablesstring | cell array of strings

Names of target variables, specified as a string or a cell array of strings. The constructor creates a Simulink.VariableUsage object for each variable name.

Example: ‘k'

Example: {'k','asdf','fuelFlow'}

Data Types: char | cell

SourceName — Name of variable sourcestring

Name of the source that defines the target variables, specified as a string. For example, you can specify the MATLAB base workspace or a data dictionary as a source. The constructor also determines and sets the SourceType property of each of the returned Simulink.VariableUsage objects.

Example: ‘base workspace'

Example: ‘myModel'

Example: ‘myDictionary.sldd'

Data Types: char

Properties

collapse all

NameName of variable or enumerated typestring

The name of the variable or enumerated data type the object describes, returned as a string.

SourceName of defining workspacestring

The name of the workspace or data dictionary that defines the described variable, returned as a string. The table shows some examples.

Source valueMeaning
'base workspace'MATLAB® base workspace
'MyModel'Model workspace for the model MyModel
'MyModel/Mask1'Mask workspace for the masked block Mask1 in the model MyModel
'sldemo_fuelsys_dd_controller.sldd'The data dictionary named 'sldemo_fuelsys_dd_controller.sldd'

The table shows some examples if you created the Simulink.VariableUsage object by using the Simulink.findVars function to find enumerated data types.

Source valueMeaning
'BasicColors.m'The enumerated type is defined in the MATLAB file 'BasicColors.m'.
''The enumerated type is defined dynamically and has no source.
'sldemo_fuelsys_dd_controller.sldd'The enumerated type is defined in the data dictionary named 'sldemo_fuelsys_dd_controller.sldd'.

SourceTypeType of defining workspacestring

The type of the workspace that defines the variable, returned as a string. The possible values are:

  • 'base workspace'

  • 'model workspace'

  • 'mask workspace'

  • 'data dictionary'

If you created the Simulink.VariableUsage object by using the Simulink.findVars function to find enumerated data types, the possible values are:

  • 'MATLAB file'

  • 'dynamic class'

  • 'data dictionary'

UsersModel blocks that use the variable or models that use the enumerated typecell array of strings

Model blocks that use the variable or models that use the enumerated type, returned as a cell array of strings. Each string names a block or model that uses the variable or enumerated type. The Simulink.findVars function populates this field.

Methods

intersectIntersection of two arrays of Simulink.VariableUsage objects
setdiffReturn difference between two arrays of Simulink.VariableUsage objects

Examples

Return a Simulink.VariableUsage object for the variable 'k' in the base workspace.

var = Simulink.VariableUsage('k','base workspace');

Return an array of Simulink.VariableUsage objects containing one object for each variable returned by the whos command.

vars = Simulink.VariableUsage(whos,'base workspace')

Return an array of Simulink.VariableUsage objects that describes all the variables in a model workspace.

hws = get_param('mymodel','ModelWorkspace');
vars = Simulink.VariableUsage(hws.whos,'MyModel')

Return an array of Simulink.VariableUsage objects that describes all the variables in a mask workspace.

maskVars = get_param('mymodel/maskblock','MaskWSVariables');
vars = Simulink.VariableUsage(maskVars,'mymodel/maskblock');
Was this topic helpful?