Documentation

Simulink.VariableUsage class

Package: Simulink

Store information about the relationship between variables and blocks in models

Description

A Simulink.VariableUsage object describes where a variable is used in models. Use this information to:

  • Prepare to permanently store the variables in files and workspaces. For more information about storing variables for a model, see Determine Where to Store Variables and Objects for Simulink Models.

  • Reduce the number of variables that you need to store by eliminating unused variables.

  • Prepare to partition variables and establish variable ownership when you work in a team.

To analyze variable usage in models, use Simulink.VariableUsage objects together with the Simulink.findVars function. The function returns and accepts Simulink.VariableUsage objects as arguments. For more information, see Simulink.findVars.

A Simulink.VariableUsage object can also describe the usage of an enumerated data type.

Only a Simulink.VariableUsage constructor or the Simulink.findVars function can set property values in a Simulink.VariableUsage object. The properties are otherwise read only.

Construction

The Simulink.findVars function returns Simulink.VariableUsage objects.

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

expand all

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

Example: 'k'

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

Data Types: char | cell

Name of the source that defines the target variables, specified as a character vector. 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

expand all

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

The name of the workspace or data dictionary that defines the described variable, returned as a character vector. 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'.

The type of the workspace that defines the variable, returned as a character vector. 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'

Model blocks that use the variable or models that use the enumerated type, returned as a cell array of character vectors. Each character vector 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?