Main Content

evalin

Evaluate expression in the model workspace of a model

Description

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.

Note

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.

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 some variables in the model workspace.

assignin(mdlWks,'myVar',5.12)
assignin(mdlWks,'myOtherVar',7.22)

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