Main Content

Simulink.data.getVariableFromGlobal

Get variable defined in context of Simulink model

Since R2024b

Description

Simulink.data.getVariableFromGlobal(modelName,variableName) retrieves the value of the variable variableName within the context of the Simulink® model or a Subsystem Reference block specified by modelName. The search includes the base workspace and the external data sources linked to the model, such as Simulink data dictionary or MAT files.

If the variable is found, the function returns its value. If the variable does not exist within the context of Simulink model or a Subsystem Reference, the function reports an error.

example

Examples

collapse all

Determine the value of a variable a in the context of the Simulink model BasicModellingData.slx.

openExample("BasicModellingData")
Simulink.data.getVariableFromGlobal("BasicModellingData","k")
ans =

      5

Input Arguments

collapse all

Model name or path to Subsystem Reference in the model, specified as a character vector or a string.

Example: "myModel"

Data Types: char | string

The name of the variable to retrieve, specified as a character vector or a string.

Example: "myVariable"

Data Types: char | string

Limitations

If there are duplicate variables that has consistent definitions in the data dictionary and MAT files, the function reports an error.

Version History

Introduced in R2024b