Main Content

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.

  1. To create a new data dictionary, in the Model Explorer, select File > New > Data Dictionary.

  2. Click Add to add objects from the drop-down list to the data dictionary.

    View of Model Explorer. On the left, a data dictionary node is expanded in the Model Hierarchy pane. On the right, the Contents pane displays the two objects contained in the Design Data section of the dictionary. More objects can be added from the Add tab.

  3. Save the data dictionary.

  4. 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.

    View of Subsystem Properties of ssref1. Data dictionary ssref1dd.sldd is added using the External Data tab.

    Alternatively, you can link the data dictionary programmatically by using any of these functions:

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.

On the left, the model hierarchy is shown. On the right, the model canvas displays the contents of the child blocks of a subsystem file. The Outport block is selected. The block parameters dialog box displays the dictionary data types in the drop-down menu for Data type.

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:

  1. Open your subsystem file. In the Simulink Editor, on the Modeling tab, click Subsystem Properties.

  2. 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.

  3. Click OK to link the MAT file.

  4. 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.

Subsystem Properties dialog box. When an external source is linked, an information message to restrict hierarchical resolution is displayed.

The hierarchical order for the symbol resolution of a child block of a subsystem reference with a linked external data source is:

  1. Mask workspaces of all blocks, starting from the child block and moving upward to the mask workspace of the subsystem file (see Masking Fundamentals).

  2. The data dictionary and MAT files linked to the subsystem file.

  3. 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.

View of Model Explorer. On the right, information for data dictionary is displayed. User can 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.

    View of model canvas and block parameters of Subsystem Reference block. The 'Permit Hierarchical Resolution' option 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

Related Topics