Simulink.VariableUsage - Store information about the relationship between variables and blocks in

        models - MATLAB ([original](https://in.mathworks.com/help/simulink/slref/simulink.variableusage.html)) ([raw](?raw))

Main Content

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:

To analyze variable usage in models, use Simulink.VariableUsage objects together with theSimulink.findVars function. The function returns and acceptsSimulink.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 aSimulink.VariableUsage object. The properties are otherwise read only.

Creation

The Simulink.findVars function returnsSimulink.VariableUsage objects.

To create variable usage objects for use as a filter when usingSimulink.findVars, use theSimulink.VariableUsage function described below.

Syntax

Description

variableUsageObj = Simulink.VariableUsage([varNames](#d126e800742),[sourceName](#d126e800777)) creates an array of Simulink.VariableUsage objects to describe the variables varNames. The constructor sets theName 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 bysourceName. You can specify varNames with variables that are not used in any loaded models.

example

Input Arguments

expand all

Names of target variables, specified as a character vector or a cell array of character vectors. The constructor creates aSimulink.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 returnedSimulink.VariableUsage objects.

Example: 'base workspace'

Example: 'myModel'

Example: 'myDictionary.sldd'

Data Types: char

Properties

expand all

This property is read-only.

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

This property is read-only.

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

Source Value Meaning
'base workspace' MATLAB base workspace
'MyModel' Model workspace for the modelMyModel
'MyModel/Mask1' Mask workspace for the masked blockMask1 in the modelMyModel
'sldemo_fuelsys_dd_controller.sldd' The data dictionary named'sldemo_fuelsys_dd_controller.sldd'

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

Source Value Meaning
'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'.

This property is read-only.

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

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

This property is read-only.

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. TheSimulink.findVars function populates this property.

Object Functions

Examples

collapse all

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

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

You can use var as a filter for theSimulink.findVars function.

Return an array of Simulink.VariableUsage objects containing one object for each variable returned by thewhos command in the base workspace.

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

Version History

Introduced in R2012b