Main Content


Evaluate expression in the model workspace of a model



result = evalin(mdlWks,expression) evaluates the expression expression in the model workspace represented by the Simulink.ModelWorkspace object represented by mdlWks. The function returns the result of the expression in result.


For setting and getting variable properties in the model workspace, consider using setVariablePart and getVariablePart instead of evalin because:

  • The functions do not create new variables or cause unintended results.

  • getVariablePart does not dirty the model.

For information on these alternatives, see Simulink.ModelWorkspace.


collapse all

Open the example model vdp.


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

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

Create some variables in the model workspace.


Evaluate the expression myLastVar = myVar + myOtherVar in the model workspace. The expression creates another variable, myLastVar, whose value is the sum of the first two variables.

evalin(mdlWks,'myLastVar = myVar + myOtherVar');

Input Arguments

collapse all

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

Expression to evaluate, specified as a character vector.

Example: 'myLastVar = myVar + myOtherVar'

Data Types: char

Output Arguments

collapse all

Result of the evaluated expression, returned as a number, structure, or other MATLAB value.

Version History

Introduced before R2006a