Main Content

hasVariable

Determine whether variable exists in the model workspace of a model

Description

varExists = hasVariable(mdlWks,varName) returns 1 if a variable whose name is varName exists in the model workspace represented by the Simulink.ModelWorkspace object mdlWks.

example

Examples

collapse all

Open the example model vdp.

openExample('simulink_general/VanDerPolOscillatorExample')

Create a Simulink.ModelWorkspace object that represents the model workspace of vdp.

mdlWks = get_param('vdp','ModelWorkspace');

Create a variable named myVar in the model workspace.

assignin(mdlWks,'myVar',5.12)

Determine whether a variable named myVar exists in the model workspace.

exists = hasVariable(mdlWks,'myVar')
exists =
   1

Input Arguments

collapse all

Target model workspace, specified as a Simulink.ModelWorkspace object.

Name of the target variable, specified as a character vector.

Example: 'myVariable'

Data Types: char

Output Arguments

collapse all

Indication of variable existence, returned as 1 (true) or 0.

Version History

Introduced in R2012a