Main Content

Simulink.data.evalinGlobal

Evaluate MATLAB expression in context of Simulink model

Description

returnValue = Simulink.data.evalinGlobal(modelName,expression) evaluates the MATLAB® expression expression within the context of the Simulink® model modelName and returns the values returned by expression. The function evaluates the expression in the following manner:

  • If a data dictionary is linked as an external data source to the model, the function evaluates the expression using data from the Design Data section of the dictionary.

  • If the model is not linked with any external data sources, the function evaluates the expression using data from the MATLAB base workspace.

  • If any MAT file is linked as an external data source to the model, the function reports an error.

example

Examples

collapse all

Evaluate the MATLAB expression myNewVariable = 237; in the context of the model vdp, which has no external data sources linked.

openExample('simulink_general/VanDerPolOscillatorExample')
Simulink.data.evalinGlobal('vdp','myNewVariable = 237;')

myNewVariable appears as a variable in the MATLAB base workspace.

Evaluate the MATLAB expression myNewEntry = true; in the context of the model sldemo_fuelsys_dd_controller, which is linked to the data dictionary sldemo_fuelsys_dd_controller.sldd.

openExample('simulink_automotive/UseDDForFuelContSysExample')
sldemo_fuelsys_dd_controller
Simulink.data.evalinGlobal('sldemo_fuelsys_dd_controller',...
'myNewEntry = true;')

myNewEntry appears as an entry in the Design Data section of the dictionary.

Confirm the creation of the entry myNewEntry in the data dictionary sldemo_fuelsys_dd_controller.sldd by viewing the dictionary in Model Explorer.

openExample('simulink_automotive/UseDDForFuelContSysExample')
sldemo_fuelsys_dd_controller'
myDictionaryObj = Simulink.data.dictionary.open(...
'sldemo_fuelsys_dd_controller.sldd');
show(myDictionaryObj)

Input Arguments

collapse all

Model name, specified as a character vector or a string.

Example: 'myTestModel'

Data Types: char | string

MATLAB expression to evaluate, specified as a character vector or a string.

Example: 'a = 5.3'

Example: 'whos'

Example: 'CurrentSpeed.Value = 290.73'

Data Types: char | string

Output Arguments

collapse all

Value returned by the specified MATLAB expression.

Limitations

If a MAT file is linked as an external data source to the model, the function reports an error.

Version History

Introduced in R2015a