| Contents | Index |
| On this page… |
|---|
A data store is a repository to which you can write data, and from which you can read data, without having to connect an input or output signal directly to the data store. Data stores are accessible across model levels, so subsystems and referenced models can use data stores to share data without using I/O ports. You can define two types of data stores:
A local data store is accessible from anywhere in the model hierarchy that is at or below the level at which you define the data store, except from referenced models. You can define a local data store graphically in a model or by creating a model workspace signal object (Simulink.Signal).
A global data store is accessible from throughout the model hierarchy, including from referenced models. Define a global data stores only in the MATLAB base workspace, using a signal object. The only type of data store that a referenced model can access is a global data store.
In general, locate a data store at the lowest level in the model that allows access to the data store by all the parts of the model that need that access. Some examples of local and global data stores appear in Data Store Examples.
For information about using referenced models, see Referencing a Model.
Embedded Coder provides a custom storage class that you can use to specify customized data store access functions in generated code. See Custom Storage Classes and GetSet Custom Storage Class for Data Store Memory.
Data stores can be useful when multiple signals at different levels of a model need the same global values, and connecting all the signals explicitly would clutter the model unacceptably or take too long to be feasible. Data stores are analogous to global variables in programs, and have similar advantages and disadvantages, such as making verification more difficult. See Data Stores and Software Verification for more information.
In some cases, you may be able to use a simpler technique, Goto blocks and From blocks, to obtain results similar to those provided by data stores. The principal disadvantage of data Goto/From links is that they generally are not accessible across nonvirtual subsystem boundaries, while an appropriately configured data store can be accessed anywhere. See the Goto and From block reference pages for more information about Goto/From links.
To create a data store, you create a Data Store Memory block or a Simulink.Signal object. The block or signal object represents the data store and specifies its properties. Every data store must have a unique name.
A Data Store Memory block implements a local data store. See Defining Data Stores with Data Store Memory Blocks.
A Simulink.Signal object can act as a local or global data store. See Defining Data Stores with Signal Objects.
Data stores implemented with Data Store Memory blocks:
Support data store initialization
Provide control of data store scope and options at specific levels in the model hierarchy
Require a block to represent the data store
Cannot be accessed within referenced models
Cannot be in a subsystem that a For Each Subsystem block represents.
Data stores implemented with Simulink.Signal objects:
Provide model-wide control of data store scope and options
Do not require a block to represent the data store
Can be accessed in referenced models, if the data store is global
Be careful not to equate local data stores with Data Store Memory blocks, and global data stores with Simulink.Signal objects. Either technique can define a local data store, and a signal object can define either a local or a global data store.
To write a signal to a data store, use a Data Store Write block, which inputs the value of a signal and writes that value to the data store.
To read a signal from a data store, use a Data Store Read block, which reads the value in the data store and outputs that value as a signal.
For Data Store Write and Data Store Read blocks, to identify the data store to be read from or written to, specify the data store name as a block parameter. See Accessing Data Stores with Simulink Blocks for more information.
You can log the values of a local or global data store data variable for all the steps in a simulation. See Logging Data Stores.
Note To use buses and arrays of buses with data stores, perform both the following procedure and Setting Up a Model to Use Data Stores with Buses and Arrays of Buses. |
The following is a general workflow for configuring data stores. You can perform the tasks in a different order, or separately from the rest, depending on how you use data stores.
Where applicable, plan your use of data stores to minimize their effect on software verification. For more information, see Data Stores and Software Verification.
Create data stores using the techniques described in Defining Data Stores with Data Store Memory Blocks or Defining Data Stores with Signal Objects. For greater reliability, consider assigning rather than inheriting data store attributes, as described in Specifying Data Store Memory Block Attributes.
Add to the model Data Store Write and Data Store Read blocks to write to and read from the data stores, as described in Accessing Data Stores with Simulink Blocks.
Configure the model and the blocks that access each data store to avoid concurrency failures when reading and writing the data store, as described in Ordering Data Store Access.
Apply the techniques described in Using Data Store Diagnostics as needed to prevent data store errors, or to diagnose them if they occur during simulation.
If you intend to generate code for your model, see Data Stores in the Simulink Coder documentation.
Benefits of using data stores with buses and arrays of buses include:
Simplifying the model layout by associating multiple signals with a single data store
Producing generated code that represents the data in the store data as structures that reflect the bus hierarchy
Writing to and reading from data stores without creating data copies, which results in more efficient data access
You cannot use a bus or array of buses that contains:
Variable-dimension signals
Frame-based signals
This procedure applies to local and global data stores, and to data stores defined with a Data Store Memory block or a Simulink.Signal object. Before performing the procedure, you must understand how to use data stores in a model, as described in Workflow for Configuring Data Stores.
To use buses and arrays of buses with data stores:
Use the Bus Editor to define a bus object whose properties match the bus data that you want to write to and read from a data store. For details, see Using the Bus Editor.
Add a data store (using a Data Store Memory block or a Simulink.Signal object) for storing the bus data.
Specify the bus object as the data type of the data store. For details, see Specifying a Bus Object Data Type.
In the Configuration Parameters > Diagnostics > Data Validity pane, set the Mux blocks used to create bus diagnostic to error. For details, see Mux blocks used to create bus signals.
If you receive error messages relating to Mux blocks, identify any Mux blocks in the model that create virtual buses. Use the Model Advisor > Simulink > Check for proper bus usage check. For details, see Check for proper bus usage.
If you use a MATLAB structure for the initial value of the data store, then in the Configuration Parameters > Diagnostics > Data Validity pane, set the Underspecified initialization detection diagnostic to error. For details, see Specifying Initial Conditions for Bus Signals and Underspecified initialization detection.
(Optional) Select individual bus elements to write to or read from a data store. For details, see Accessing Specific Bus and Matrix Elements.
![]() | Working with Data Stores | Defining Data Stores with Data Store Memory Blocks | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |