Main Content

clear

Clear variables from the model workspace of a model

Description

example

clear(mdlWks) removes all variables from the model workspace represented by the Simulink.ModelWorkspace object mdlWks.

example

clear(mdlWks, varName) removes the variable with the name varName from the model workspace mdlWks.

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 with value 5.12 in the model workspace.

assignin(mdlWks,'myVar',5.12)

Clear all variables from the model workspace, including myVar.

clear(mdlWks)

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 var1 with value 5.12 in the model workspace.

assignin(mdlWks,'var1',5.12)

Create another variable named var2 with value 7.5 in the model workspace.

assignin(mdlWks,'var2',7.5)

Clear variable var1 from the model workspace.

clear(mdlWks, 'var1')

Input Arguments

collapse all

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

Name of variable to remove, specified as a string or a character vector.

Example:

Version History

Introduced before R2006a