Main Content

getVariablePart

Get value of variable property in model workspace

Description

varValue = getVariablePart(mdlWks,varName.Property) returns the value of the variable property named varName.Property that exists in the model workspace represented by the Simulink.ModelWorkspace object mdlWks.

If the value of the variable property is a handle to a handle object (such as Simulink.Parameter), getVariablePart returns a copy of the handle.

Using getVariablePart is preferable to using evalin for getting variable properties in the model workspace because:

  • The function does not dirty the model.

  • Use of the function does not result in the creation of a new variable or other unintended results.

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 structure named myStruct with fields a, b, and c.

aStruct.a = 10;
aStruct.b = {1,2,3,4,5};
aStruct.c = Simulink.Parameter(7);
mdlWks.assignin('myStruct',aStruct); 

Return the values of the structure fields. Store the values in varValuea, varValueb, and varValuec.

varValuea = getVariablePart(mdlWks,'myStruct.a');
varValueb = getVariablePart(mdlWks,'myStruct.b{1}');
varValueC = getVariablePart(mdlWks,'myStruct.c.Value');

Input Arguments

collapse all

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

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

Example: 'myVariable.Property'

Data Types: char

Output Arguments

collapse all

Value of the variable property, returned as a number, structure, or other MATLAB value.

If the value of the variable property is a handle to a handle object (such as Simulink.Parameter), getVariablePart returns a copy of the handle.

Version History

Introduced in R2018b