Main Content

assignin

Assign value to variable in the model workspace of a model

Description

assignin(mdlWks,varName,varValue) assigns the value varValue to the MATLAB variable varName in the model workspace represented by the Simulink.ModelWorkspace object mdlWks. If the variable does not exist, assignin creates it.

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

assignin(mdlWks,'myVar',5.12)

Input Arguments

collapse all

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

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

Example: 'myVar'

Data Types: char

Value to assign to the target variable, specified as a valid value. For example, you can specify a literal number, a structure, or an expression that evaluates to a valid value.

If you specify the name of a handle object, such as a Simulink.Parameter object, use the copy function to create a separate copy of the object.

Example: 5.12

Example: struct('a',5.12,'b',7.22)

Example: Simulink.Parameter(5.12)

Example: copy(myExistingParameterObject)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | table | cell | categorical | datetime | duration | calendarDuration | fi
Complex Number Support: Yes

Version History

Introduced before R2006a