Manage Subsystem Reference Data Using External Data Sources
You can link external data sources, such as data dictionaries and MAT files, to a subsystem file to store variables, objects, and interfaces. By using external data sources, you can define and reuse all types of data and interfaces in the child blocks and instances of the subsystem file. A subsystem file supports multiple external data sources. The scope of data you define in the external data sources is within the boundary of the Subsystem Reference block.
Link a Data Dictionary to a Subsystem File
Linking a data dictionary to a subsystem reference provides you with multiple capabilities, such as data storage, data-model linkage, and version handling. For more information, see What Is a Data Dictionary?
Create a new data dictionary or open an existing data dictionary.
To create a new data dictionary, in the Model Explorer, select File > New > Data Dictionary.
Click Add to add objects from the drop-down list to the data dictionary.
Save the data dictionary.
To link the data dictionary:
Open your subsystem file. In the Simulink® Editor, on the Modeling tab, click Subsystem Properties.
In the Subsystem Properties dialog box, navigate to the External Data tab and in the Data Dictionary section, click Browse to locate and open your data dictionary.
Click OK to link the data dictionary.
Alternatively, you can link the data dictionary programmatically by using any of these functions:
set_param
function:set_param("ssref1","DataDictionary","ssref1dd.sldd")
Simulink.data.dataSource.addSource
function:Simulink.data.dataSource.addSource("ssref1","ssref1dd.sldd")
After you have linked the data dictionary and saved your subsystem file, the data dictionary and its contents appear in the Model Explorer as an external data source for the subsystem file.
You can use variables and data types defined in the data dictionary within the subsystem reference boundary.
For example, select data types defined in the linked data dictionary from the Data type list in the child blocks and instances of your Subsystem Reference block.
Link a MAT File to a Subsystem File
Linking a MAT file to a subsystem reference enables you to store variables, data arrays, and other MATLAB® workspace information with an efficient use of storage space and with faster data loading and saving operations. For information on MAT files, see Save and Load Parts of Variables in MAT-Files.
To link a MAT file:
Open your subsystem file. In the Simulink Editor, on the Modeling tab, click Subsystem Properties.
In the Subsystem Properties dialog box, navigate to the External Data tab and in the Additional data sources section, click Browse to locate and open your MAT file.
Click OK to link the MAT file.
Save the subsystem file.
Alternatively, you can link the MAT-file programmatically by using the Simulink.data.dataSource.addSource
function:
Simulink.data.dataSource.addSource("ssref1","SampleValues.mat")
Symbol Resolution Process
To determine model behavior, Simulink tries to find the values of the symbols used to define model entities. To resolve a symbol, Simulink searches through the accessible workspaces in a hierarchical order for a variable or object whose name is same as the symbol name. For more information, see Symbol Resolution.
When you link an external data source to a subsystem file, the symbol resolution for any child block of the subsystem reference is restricted within the boundary of the Subsystem Reference block. The Subsystem Properties dialog box displays this behavior change in symbol resolution when in the External Data tab.
The hierarchical order for the symbol resolution of a child block of a subsystem reference with a linked external data source is:
Mask workspaces of all blocks, starting from the child block and moving upward to the mask workspace of the subsystem file (see Masking Fundamentals).
The data dictionary and MAT files linked to the subsystem file.
MATLAB base workspace, only if the linked data dictionary has access to the base workspace. When only a MAT file is linked, base workspace cannot be accessed.
To allow access to the MATLAB base workspace, in the Model Explorer, select your data dictionary and select Enable dictionary access to base workspace.
Considerations and Limitations
There are some considerations when you link external data sources to a subsystem file.
As the hierarchical symbol resolution is restricted, the Permit Hierarchical Resolution option on the Subsystem Reference block parameter dialog box is disabled and set to
None
.The enumerated data types defined in the data dictionary of a subsystem reference are also available outside the subsystem reference boundary.
When you link only a MAT file to a subsystem file, Simulink cannot access the MATLAB base workspace for symbol resolution. To enable symbol resolution for data types defined in the base workspace, such as enumerated data types and variant parameter banks, link a data dictionary and enable access to the base workspace.
See Also
Blocks
Functions
set_param
|get_param
|matfile
|Simulink.data.dataSource.addSource
|Simulink.data.dataSource.removeSource