Documentation

Simulink.data.assigninGlobal

Modify variable values in context of Simulink model

Syntax

Simulink.data.assigninGlobal(modelName,varName,varValue)

Description

example

Simulink.data.assigninGlobal(modelName,varName,varValue) assigns the value varValue to the variable or data dictionary entry varName in the context of the Simulink model modelName. assigninGlobal creates the variable or data dictionary entry if it does not already exist. The function operates in the Design Data section of the data dictionary that is linked to the target model or in the MATLAB base workspace if the target model is not linked to any data dictionary.

If the target model is linked to a data dictionary that references other dictionaries, assigninGlobal searches for varName in the entire dictionary hierarchy. If assigninGlobal does not find a matching entry, the function creates an entry in the dictionary that is linked to the target model.

Examples

collapse all

Create a variable myNewVariable with value 237 in the context of the Simulink model vdp.slx, which is not linked to any data dictionary. myNewVariable appears as a variable in the MATLAB base workspace.

Simulink.data.assigninGlobal('vdp','myNewVariable',237)

Create a variable myNewEntry with value true in the context of the Simulink model sldemo_fuelsys_dd_controller.slx, which is linked to the data dictionary sldemo_fuelsys_dd_controller.sldd. The entry myNewEntry appears in the Design Data section of the dictionary.

Simulink.data.assigninGlobal('sldemo_fuelsys_dd_controller',...
'myNewEntry',true)

Confirm the addition of myNewEntry to the data dictionary sldemo_fuelsys_dd_controller.sldd by viewing the dictionary in Model Explorer.

myDictionaryObj = Simulink.data.dictionary.open(...
'sldemo_fuelsys_dd_controller.sldd');
show(myDictionaryObj)

Input Arguments

collapse all

Name of target Simulink model, specified as a character vector.

Example: 'myTestModel'

Data Types: char

Name of target variable or data dictionary entry, specified as a character vector.

Example: 'myTargetVariable'

Data Types: char

Value to assign to variable or data dictionary entry, specified as a MATLAB expression that returns any valid data type or data dictionary content.

Example: 27.5

Example: myBaseWorkspaceVariable

Example: Simulink.Parameter

Tips

  • assigninGlobal helps you transition Simulink models to using data dictionaries. You can use the function to assign values to model variables before and after linking a model to a data dictionary.

Introduced in R2015a

Was this topic helpful?