Main Content

Simulink.data.dataSource.addSource

Add external data source to model

Since R2024b

Description

Simulink.data.dataSource.addSource(modelName,nameOfExternalSource) associates an external data source, such as a MAT file or a data dictionary, to a Simulink® model or a Subsystem File specified by modelName. This allows the model to use the variables and data from these external data sources during simulation, compilation, and other model operations.

You can add one data dictionary and multiple MAT files as external data sources to a model and a Subsystem File.

example

Examples

collapse all

Add an external data source BasicModellingDataDefinitions.mat to the model BasicModellingData.

openExample("BasicModellingData")
Simulink.data.dataSource.addSource("BasicModellingData","BasicModellingDataDefinitions.mat")

Add an external data source myDictionary.sldd to the Subsystem File SSREF1.

openExample('subsystem_reference/SubsystemReferenceExample')
Simulink.data.dataSource.addSource("SSREF1","myDictionary.sldd")

The scope of the data is within the boundary of the Subsystem File.

Input Arguments

collapse all

Path or handle of a model or subsystem file, specified as a character vector or string.

Example: "myModel"

Data Types: char | string

Name of the external data source, specified as a character vector or string. Data source can be a MAT file or a data dictionary.

  • MAT file — Name of MAT file, including file extension

  • Data dictionary — Name of data dictionary, including file extension

Example: "myMatFile.mat"

Example: "myDictionary.sldd"

Data Types: char | string

Alternatives

Use the Model Explorer to navigate to the External Data tab. Under Additional data sources, browse for the data source and add to the model.

Version History

Introduced in R2024b