| Using Simulink | ![]() |
Working with Data Stores
Data stores are signals that are accessible at any point in a model hierarchy at or below the level in which they are defined. Because they are accessible across model levels, data stores allow subsystems and model references to share data without having to use I/O ports to pass the data from level to level (see Data Store Examples for examples of using data stores to share data among subsystems and model references).
Defining Data Stores
Defining a data store entails creating an object whose properties specify the properties of the data store. You can use either Data Store Memory blocks or instances of Simulink.Signal class to define data stores. Each approach has advantages. Data Store Memory blocks give you more control over the scope of data stores within a model and allow initialization of data stores. Simulink.Signal objects avoid cluttering a model with blocks and allows data stores to be visible across model reference boundaries.
Using Data Store Memory Blocks to Define Data Stores
To use a Data Store Memory block to define a data store, drag an instance of the block into the model at the topmost level from which you want the data store to be visible. For example, to define a data store that is visible at every level in a model (except in model references), drag the Data Store Memory block into the root level of the model. To define a data store that is visible only in a particular subsystem (and the subsystems that it contains), drag the block into the subsystem. Once you have created the Data Store Memory block, use its parameter dialog box to define the data stores properties, including its name, data type, complexity.
Using Signal Objects to Define Data Stores
To use a signal object to define a data store, create an instance of Simulink.Signal object in a workspace that is visible to every model that needs to access the data store. For example, to define a data store that is visible to a top model and all the models that it references, use the Model Explorer or MATLAB commands to create the signal object in the base (i.e., MATLAB) workspace. To define a data store that is visible only in a particular model, create the signal object in the model's workspace (see Changing Model Workspace Data). You can use Simulink.Signal objects to define data stores that are visible in only one model (a local data store) or in a top model and the models that the top model references (a global data store).
When creating the object, assign it to a workspace variable whose name is the name you want to be assigned to the data store. Once you have created the object, use the Model Explorer or MATLAB commands to set the following properties of the signal object to the values that you want the corresponding data store property to have.
For example, the following commands defines a data store named Error in the MATLAB workspace:
Error = Simulink.Signal; Error.Description = 'Use to signal that subsystem output is invalid'; Error.DataType = 'boolean'; Error.Complexity = 'real'; Error.Dimensions = 1; Error.SamplingMode='Sample based'; Error.SampleTime = 0.1;
Accessing Data Stores
To set the value of a data store at each time step, create an instance of a Data Store Write block at the level of your model that computes the value, set its Data store name parameter to the name of the data store to be updated, and connect the output of the block that computes the value to the input of the Data Store Write block, e.g.,
To get the value of a data store at each time step, create an instance of a Data Store Read block at the level of your model that needs the value, set the block's Data store name parameter to the name of the data store to be read, and connect the output of the data store read block to the input of the block that need's the data store's value, e.g.,
When connected to a global data store, a data store access block displays the word Global above the data store's name.
This is done to remind you that the data store is defined by a signal object in the MATLAB workspace rather than by a Data Store Memory block.
Data Store Examples
The following examples illustrate the use of these constructs to define and access data stores.
Local Data Store Example
The following model illustrates creation and access of a local data store, i.e., a data store that is visible only in a model or particular subsystem.
This model uses a data store to permit subsystem A to signal that its output is invalid. If subsystem A's output is invalid, the model uses the output of subsystem B.
Global Data Store Example
The following model replaces the subsystems of the previous example with functionally identical submodels to illustrate use of a global data store to share data in a model reference hierarchy.
In this example, the top model uses a signal object in the MATLAB workspace to define the error data store. This is necessary because only data stores defined by signal objects in the MATLAB workspace are visible across model boundaries.
| Model Workspace Dialog Box | The Model Advisor | ![]() |
© 1994-2005 The MathWorks, Inc.