Determine whether variable exists in the model workspace of a model
varExists = hasVariable(mdlWks,varName)
example
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.
varExists
mdlWks
varName
1
Simulink.ModelWorkspace
collapse all
Open the example model vdp.
vdp
open_system('vdp')
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.
myVar
assignin(mdlWks,'myVar',5.12)
Determine whether a variable named myVar exists in the model workspace.
exists = hasVariable(mdlWks,'myVar')
exists = 1
Target model workspace, specified as a Simulink.ModelWorkspace object.
Name of the target variable, specified as a character vector.
Example: 'myVariable'
'myVariable'
Data Types: char
char
0
Indication of variable existence, returned as 1 (true) or 0.
get_param | Simulink.ModelWorkspace
get_param