Main Content

Simulink.WorkspaceVar

Store information about workspace variables and blocks that use them

Simulink.WorkspaceVar is not recommended. Use Simulink.VariableUsage instead.

Description

A Simulink.WorkspaceVar object describes attributes of a workspace variable and lists the blocks that use the variable.

Creation

The Simulink.findVars function returns one or more Simulink.WorkspaceVar objects that embody the results of searching for variables.

Only the Simulink.WorkspaceVar function can set any field value in a Simulink.WorkspaceVar object. The fields are otherwise read-only.

Description

varObj = Simulink.WorkspaceVar(varNames,wkspName) creates an array of Simulink.WorkspaceVar 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 Workspace property of all the objects to the workspace specified by wkspName. 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 a Simulink.WorkspaceVar object for each variable name. You can specify varNames with variables that are not used in any loaded models.

Example: 'k'

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

Data Types: char | cell

Name of the workspace that defines the target variables, specified as a character vector. For example, you can specify the MATLAB® base workspace. The constructor also determines and sets the WorkspaceType property of each of the returned Simulink.WorkspaceVar objects.

Example: 'base workspace'

Example: 'myModel'

Example: 'myDictionary.sldd'

Data Types: char

Properties

expand all

This property is read-only.

Name of the variable described by the object, returned as a character vector.

This property is read-only.

Name of the workspace that contains the variable, returned as a character vector. 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.

This property is read-only.

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

  • 'base' — The base workspace

  • 'model' — A model workspace

  • 'mask' — A mask workspace

This property is read-only.

Users of the variable, returned as a cell array of character vectors. Each character vector identifies a block that uses the variable. The Simulink.findVars function populates this property.

Object Functions

Examples

collapse all

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

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

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

vars = Simulink.WorkspaceVar(who,WkspName)

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

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

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

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

Version History

Introduced in R2010a