Documentation

Simulink.VariableUsage

Store information about the relationship between variables and blocks in models

Description

ASimulink.VariableUsageobject 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, seeDetermine 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, useSimulink.VariableUsageobjects together with theSimulink.findVarsfunction. The function returns and acceptsSimulink.VariableUsageobjects as arguments. For more information, seeSimulink.findVars.

ASimulink.VariableUsageobject can also describe the usage of an enumerated data type.

只有一个Simulink.VariableUsageconstructor or theSimulink.findVarsfunction can set property values in aSimulink.VariableUsageobject. The properties are otherwise read only.

Creation

TheSimulink.findVarsfunction returnsSimulink.VariableUsageobjects.

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

Syntax

variableUsageObj = Simulink.VariableUsage(varNames,sourceName)

Description

example

variableUsageObj = Simulink.VariableUsage(varNames,sourceName)creates an array ofSimulink.VariableUsageobjects to describe the variablesvarNames. The constructor sets theNameproperty of each object to one of the variable names specified byvarNames, and sets theSourceproperty of all the objects to the source specified bysourceName. You can specifyvarNameswith 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 aSimulink.VariableUsageobject 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 theSourceTypeproperty of each of the returnedSimulink.VariableUsageobjects.

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.

SourceValue Meaning
'base workspace' MATLAB®base workspace
'MyModel' Model workspace for the modelMyModel
'MyModel/Mask1' Mask workspace for the masked blockMask1in 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对象通过使用theSimulink.findVarsfunction to find enumerated data types.

SourceValue 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:

  • 'base workspace'

  • 'model workspace'

  • 'mask workspace'

  • 'data dictionary'

If you created theSimulink.VariableUsage对象通过使用theSimulink.findVarsfunction to find enumerated data types, the possible values are:

  • 'MATLAB file'

  • 'dynamic class'

  • 'data dictionary'

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.findVarsfunction populates this property.

Object Functions

Examples

collapse all

Return aSimulink.VariableUsageobject for a variablekin the base workspace.

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

您可以使用varas a filter for theSimulink.findVarsfunction.

Return an array ofSimulink.VariableUsageobjects containing one object for each variable returned by thewhoscommand in the base workspace.

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

Return an array ofSimulink.VariableUsageobjects that describes all the variables in a model workspace.

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

Return an array ofSimulink.VariableUsageobjects that describes all the variables in a mask workspace.

maskVars = get_param('mymodel/maskblock','MaskWSVariables'); vars = Simulink.VariableUsage(maskVars,'mymodel/maskblock');

Introduced in R2012b

Was this topic helpful?