Simulink.VariableUsage class

Package: Simulink

Get information about workspace variables and blocks that use them

Tip

Only a Simulink.VariableUsage constructor can set any field value in a Simulink.VariableUsage object. The fields 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.

Construction

Create a Simulink.VariableUsage object as follows.

var = Simulink.VariableUsage (VarName, WkspName), where both arguments are strings, returns a Simulink.VariableUsage object with Name VarName and Workspace WkspName. The inputs need not exist in the model. Simulink® will provide a WorkspaceType automatically.

vars = Simulink.VariableUsage (VarNames, WkspName), where VarNames is a cell array of strings, returns a vector of Simulink.VariableUsage objects, each with a specified name and Workspace = WkspName.

Properties

Name

The name of the variable described by the Simulink.VariableUsage object

Source

The name of the workspace in which the variable resides, for example:

Workspace valueMeaning
'base workspace'The MATLAB® base workspace
'MyModel'The model workspace for the model MyModel.
'MyModel/Mask1'The mask workspace for the masked block Mask1 in the model MyModel.

SourceType

The type of workspace in which the variable resides. The possible values are:

  • 'base workspace'

  • 'model workspace'

  • 'mask workspace'

Users

A cell array of strings. Each string names a block that uses the variable. Simulink.findVars populates this field.

Methods

[VarsOut] = VarsIn1.setdiff (VarsIn2) — Calls setdiff to return the difference between VarsIn1 and VarsIn2. The arguments and return value are vectors of Simulink.VariableUsage objects.

[VarsOut] = VarsIn1.intersect (VarsIn2) — Calls intersect to return the intersection between VarsIn1 and VarsIn2. The arguments and return value are vectors of Simulink.VariableUsage objects.

Examples

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

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

Return a vector of Simulink.VariableUsage objects, one object for each variable returned by whos.

[vars] = Simulink.VariableUsage (whos,  WkspName)

Create a vector of Simulink.VariableUsage objects that describes all the variables in a model workspace

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

Create a vector 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?