Define data store
Simulink / Signal Routing
The Data Store Memory block defines and initializes a named shared data store, which is a memory region usable by Data Store Read and Data Store Write blocks that specify the same data store name.
The location of the Data Store Memory block that defines a data store determines which Data Store Read and Data Store Write blocks can access the data store:
If the Data Store Memory block is in the top-level system, Data Store Read and Data Store Write blocks anywhere in the model can access the data store.
If the Data Store Memory block is in a subsystem, Data Store Read and Data Store Write blocks in the same subsystem or in any subsystem below it in the model hierarchy can access the data store.
Data Store Read or Data Store Write blocks cannot access a Data Store Memory block that is either in a model that contains a Model block or in a referenced model.
Do not include a Data Store Memory block in a For Each subsystem.
Obtaining correct results from data stores requires ensuring that data store reads and writes occur in the expected order. For details, see:
You can use Simulink.Signal
objects in addition
to, or instead of, Data Store Memory blocks to define data stores. A data
store defined in the base workspace with a signal object is a
global data store. Global data stores are accessible to every
model, including all referenced models. See Data Stores for more
information.
Data store name
— Name for the data storeA
(default) | character vector | stringSpecify a name for the data store you are defining with this block. Data Store Read and Data Store Write blocks with the same name can read from, and write to, the data store initialized by this block. The name can represent a Data Store Memory block or a sign object defined to be a data store.
Block Parameter:
DataStoreName |
Type: character vector |
Values: 'A' |
... |
Default:
'A' |
Rename All
— Rename this data store throughout the modelRename this data store everywhere the Data Store Read and Data Store Write blocks use it in a model.
You cannot use Rename All to rename a data store if you:
Use a Simulink.Signal
object in a
workspace to control the code generated for the data
store
Use a Simulink.Signal
object instead
of a Data Store Memory block to define
the data store
You must instead rename the corresponding
Simulink.Signal
object from Model Explorer. For
an example, see Rename Data Store Defined by Signal Object.
Corresponding Data Store Read/Write blocks
— Path to connected Data Store Read/Write blocksList all the Data Store Read and Data Store Write blocks that have the same data store name as the current block, and that are in the current system or in any subsystem below it in the model hierarchy. Clicking a block path displays and highlights that block in your model.
Initial value
— Initial value of data store0
(default) | scalar | vector | matrix | N-D arraySpecify the initial value or values of the data store. The Minimum parameter specifies the minimum value for this parameter, and the Maximum parameter specifies the maximum value.
If you specify a nonscalar value and set
Dimensions to -1
(the
default), the data store has the same dimensions as the array. Data that
you write to the data store (by using Data Store Write
blocks) must have these dimensions.
If you set the Dimensions parameter to a value
other than -1
, the initial value dimensions must
match the dimensions that you specify, unless the initial value is a
scalar or a MATLAB® structure. If you specify a scalar, each element of the
data store uses the scalar as the initial value. Use this technique to
apply the same initial value (the scalar that you specify) to each
element without manually matching the dimensions of the initial value
with the dimensions of the data store.
To use this block to initialize a nonvirtual bus signal, specify the
initial value as a MATLAB structure and set the model configuration parameter Underspecified initialization detection to Simplified
. For more information about
initializing nonvirtual bus signals using structures, see Specify Initial Conditions for Bus Signals.
Block Parameter:
InitialValue |
Type: character vector |
Values: scalar | vector | matrix | N-D array |
Default:
'0' |
Minimum
— Minimum output value for range checking[]
(default) | scalarSpecify the minimum value that the block should output. The default
value is []
(unspecified). This number must be a
finite real double scalar value.
Note
If you specify a bus object as the data type for this block, do
not set the minimum value for bus data on the block. Simulink
ignores this setting. Instead, set the minimum values for bus
elements of the bus object specified as the data type. For
information on the Minimum property of a bus element, see Simulink.BusElement
.
Simulink® uses the minimum value to perform:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters).
Simulation range checking (see Specify Signal Ranges).
Automatic scaling of fixed-point data types.
Optimization of the code that you generate from the model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Block Parameter:
OutMin |
Type: character vector |
Values: scalar |
Default: '[
]' |
Maximum
— Maximum output value for range checking[]
(default) | scalarSpecify the maximum value that the block should output. The default
value is []
(unspecified). This number must be a
finite real double scalar value.
Note
If you specify a bus object as the data type for this block, do
not set the maximum value for bus data on the block. Simulink
ignores this setting. Instead, set the maximum values for bus
elements of the bus object specified as the data type. For
information on the Maximum property of a bus element, see Simulink.BusElement
.
Simulink uses the maximum value to perform:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters).
Simulation range checking (see Specify Signal Ranges).
Automatic scaling of fixed-point data types.
Optimization of the code that you generate from the model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Block Parameter:
OutMax |
Type: character vector |
Values: scalar |
Default: '[
]' |
Data type
— Output data typeInherit: auto
(default) | double
| single
| half
| int8
| uint8
| int16
| uint16
| int32
| uint32
| int64
| uint64
| boolean
| fixdt(1,16,0)
| fixdt(1,16,2^0,0)
| string
| Enum: <class name>
Specify the output data type. You can set it to:
A rule that inherits a data type (for example,
Inherit: auto
).
The name of a built-in data type (for example,
single
).
The name of a data type object (for example, a
Simulink.NumericType
object).
An expression that evaluates to a data type (for example,
fixdt(1,16,0)
). Do not specify a bus
object as the data type in an expression; use Bus:
<object name>
to specify a bus data
type.
Click the Show data type assistant
button to display the Data Type Assistant,
which helps you set the data type attributes. For more information, see Specify Data Types Using Data Type Assistant.
Block Parameter:
OutDataTypeStr |
Type: character vector |
Values:
'Inherit: auto' | 'double' | 'single' | 'half' | 'int8'
| 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' |
'int64' | 'uint64' | 'boolean' | 'fixdt(1,16,0)' |
'fixdt(1,16,2^0,0)' | 'string' | 'Enum: <class
name>' |
Default:
'Inherit: auto' |
Lock output data type setting against changes by the fixed-point tools
— Prevent fixed-point tools from overriding Output data typeoff
(default) | on
Select this parameter to prevent the fixed-point tools from overriding the Output data type you specify on the block. For more information, see Use Lock Output Data Type Setting (Fixed-Point Designer).
Block Parameter:
LockScale |
Type: character vector |
Values:
'off' | 'on' |
Default:
'off' |
Dimensions (-1 to infer from Initial value)
— Dimensions of data store-1
(default) | scalar | vector | matrixDimensions of the data store. The default value,
-1
, enables you to set the dimensions of the data
store by using the Initial value parameter.
However, in this case, you cannot use scalar expansion with the initial
value. You must specify the initial value by using an array that has the
dimensions that you want.
If you use a value other than -1
, specify the same
dimensions as the dimensions of the Initial value
parameter, unless you specify the initial value as a scalar (for scalar
expansion) or a MATLAB structure. If the data store represents an array of buses,
and if you use a MATLAB structure for the initial value, you can specify
dimensions to initialize the array of buses with this structure.
Block Parameter:
Dimensions |
Type: character vector |
Values: scalar | vector | matrix |
Default:
'-1' |
Interpret vector parameters as 1-D
— Interpret vectors as 1-Don
(default) | off
Specify that the data store interpret vector initial values as one-dimensional.
By default, MATLAB represents vector data as matrices, which have two
dimensions. For example, MATLAB represents the vector [1 2 3]
as a
1-by-3 matrix.
When you select this parameter, the data store represents vector data
by using only one dimension instead of two. For example, if you specify
an initial value of [1 2 3]
, the data store stores a
one-dimensional vector with three elements.
For more information, see Determine the Output Dimensions of Source Blocks.
Block Parameter:
VectorParams1D |
Type: character vector |
Values: 'off' |
'on' |
Default:
'on' |
Signal type
— Complexity of data store valuesauto
(default) | real
| complex
Specify the numeric type, real or complex, of the values in the data store.
Block Parameter:
SignalType |
Type: character vector |
Values:
'auto' | 'real' | 'complex' |
Default:
'auto' |
Share across model instances
— Allow Model blocks to read from the same data storeoff
(default) | on
In a single model reference hierarchy, when you use multiple Model blocks to refer to a model that contains a Data Store Memory block, by default, each instance of the referenced model (each Model block) reads from and writes to a separate copy of the data store. When you select Share across model instances, instead of interacting with a separate copy, all of the instances read from and write to the same data store.
When you set the model configuration parameter Code
interface packaging to Reusable
function
to generate reentrant code from a model
(Simulink
Coder™), a data store with Share across model
instances selected appears in the code as a global symbol
that the generated entry-point functions access directly. For example, a
global symbol is a global variable or a field of a global structure
variable. Therefore, each call that your code makes to the entry-point
functions (each instance of the model) shares the data.
For an example, see Share Data Store Between Instances of a Reusable Algorithm. For more information, see Share Data Among Referenced Model Instances.
Block Parameter:
ShareAcrossModelInstances |
Type: character vector |
Values:
'off' | 'on' |
Default:
'off' |
Data store name must resolve to Simulink signal object
— Require data store name resolve to Simulink signal objectoff
(default) | on
Specify that Simulink software, when compiling the model, searches the model and
base workspace for a Simulink.Signal
object
having the same name, as described in Symbol Resolution. If
Simulink does not find such an object, the compilation stops with
an error. Otherwise, Simulink compares the attributes of the signal object to the
corresponding attributes of the Data Store Memory block. If the block
and the object attributes are inconsistent, Simulink halts model compilation and displays an error.
Block Parameter:
StateMustResolveToSignalObject |
Type: character vector |
Values:
'off' | 'on' |
Default:
'off' |
Signal object class
— Custom storage class packageSimulink.Signal
(default) | object of a class that is derived from
Simulink.Signal
Choose a custom storage class package by selecting a signal object
class that the target package defines. For example, to apply custom
storage classes from the built-in package mpt
, select
mpt.Signal
. Unless you use an ERT-based
code generation target with Embedded Coder® software, custom storage classes do not affect the
generated code.
For information about storage classes, see C Code Generation Configuration for Model Interface Elements (Simulink Coder). For information about custom storage classes, see Organize Parameter Data into a Structure by Using Struct Storage Class (Embedded Coder).
Block Parameter:
StateSignalObject |
Type: character vector |
Values:
'Simulink.Signal' | ... |
Default:
'Simulink.Signal' |
Storage class
— Storage class for code generationAuto
(default) | Model default
| ExportedGlobal
| ImportedExtern
| ImportedExternPointer
| BitField (Custom)
| Volatile (Custom)
| ExportToFile (Custom)
| ImportFromFile (Custom)
| FileScope (Custom)
| AutoScope (Custom)
| Struct (Custom)
| GetSet (Custom)
| Reusable (Custom)
Applies the storage class or custom storage class that you select from the list. For information about storage classes, see C Code Generation Configuration for Model Interface Elements (Simulink Coder). For information about custom storage classes, see Organize Parameter Data into a Structure by Using Struct Storage Class (Embedded Coder).
Use Signal object class to select custom storage
classes from a package other than Simulink
.
To programmatically set this parameter, use
StateStorageClass
or
StateSignalObject
. See C Code Generation Configuration for Model Interface Elements (Simulink Coder).
Block Parameter:
StateStorageClass |
Type: character vector |
Values:
'Auto' |
'Model default' | 'ExportedGlobal' | 'ImportedExtern' |
'ImportedExternPointer' | 'Custom' | ... |
Default:
'Auto' |
TypeQualifier
— Storage type qualifier''
(default) | const
| volatile
| ...Specify a storage type qualifier such as const
or volatile
.
Note
TypeQualifier will be removed in a future release. To apply storage type qualifiers to data, use custom storage classes and memory sections. Unless you use an ERT-based code generation target with Embedded Coder, custom storage classes and memory sections do not affect the generated code.
During simulation, the block uses the following values:
The initial value of the signal object to which the state name is resolved
Minimum and Maximum values of the signal object
For more information, see Data Objects.
To enable this parameter, set Code generation storage class to ExportedGlobal
, ImportedExtern
, ImportedExternPointer
, or Model default
. This parameter is hidden unless you previously set its value.
Block Parameter: RTWStateStorageTypeQualifier |
Type: character vector |
Values:
'' | 'const' |
'volatile' | ... |
Default: '' |
Detect Read Before Write
— Action when model attempts to read data before writing in current time
stepwarning
(default) | none
| error
Select the diagnostic action to take if the model attempts to read data from a data store to which it has not written data in this time step. See also the Detect read before write diagnostic in the Data Store Memory block section of the Model Configuration Parameters > Diagnostics > Data Validity pane.
None
— Produce no response.
Warning
— Display a warning and
continue the simulation.
Error
— Terminate the simulation
and display an error.
Block Parameter:
ReadBeforeWriteMsg |
Type: character vector |
Values:
'none' | 'warning' | 'error' |
Default:
'warning' |
Detect Write After Read
— Action when block attempts to write after reading in same time stepwarning
(default) | none
| error
Select the diagnostic action to take if the model attempts to write data to the data store after previously reading data from it in the current time step. See also the Detect write after read diagnostic in the Data Store Memory block section of the Model Configuration Parameters > Diagnostics > Data Validity pane.
None
— Produce no response.
Warning
— Display a warning and
continue the simulation.
Error
— Terminate the simulation
and display an error.
Block Parameter:
WriteAfterReadMsg |
Type: character vector |
Values:
'none' | 'warning' | 'error' |
Default:
'warning' |
Detect Write After Write
— Action when model writes twice in same time stepwarning
(default) | none
| error
Select the diagnostic action to take if the model attempts to write data to the data store twice in succession in the current time step. See also the Detect write after write diagnostic in the Data Store Memory block section of the Model Configuration Parameters > Diagnostics > Data Validity pane.
None
— Produce no response.
Warning
— Display a warning and
continue the simulation.
Error
— Terminate the simulation
and display an error.
Block Parameter:
WriteAfterWriteMsg |
Type: character vector |
Values:
'none' | 'warning' | 'error' |
Default:
'warning' |
Log data store data
— Log data store dataoff
(default) | on
Select this option to save the values of this signal to the MATLAB workspace during simulation. See Signal Logging for details.
Block Parameter:
DataLogging |
Type: character vector |
Values:
'off' | 'on' |
Default:
'off' |
Logging name
— Name associated with logged signal dataUse data store name
(default) | Custom
Use this pair of controls, consisting of a list box and an edit field, to specify the name associated with logged signal data.
Simulink uses the signal name as its logging name by default. To
specify a custom logging name, select Custom
from the list box and enter the custom name in the adjacent edit
field.
Block Parameter:
DataLoggingNameMode |
Type: character vector |
Values:
'SignalName' | 'Custom' |
Default:
'' |
Note
If you set DataLoggingNameMode
to
Custom
, you must specify the name
associated with logged signal data using the
DataLoggingName
parameter.
Block Parameter:
DataLoggingName |
Type: character vector |
Values: character vector |
Default:
'' |
Limit data points to last
— Discard all but the last N data points5000
| non-zero integerDiscard all but the last N
data points, where
N
is the number that you enter in the adjacent
edit field. For more information, see Log Data Stores.
Block Parameter:
DataLoggingMaxPoints |
Type: character vector |
Values: nonzero integer |
Default:
'5000' |
Decimation
— Log every Nth data point2
(default) | integerLog every N
th data point, where
N
is the number that you enter in the adjacent
edit field. For example, suppose that your model uses a fixed-step
solver with a step size of 0.1
s. If you select this
option and accept the default decimation value (2
),
Simulink records data points for this signal at times
0.0
, 0.2
,
0.4
, and so on. For more information, see Log Data Stores.
Block Parameter:
DataLoggingLimitDataPoints |
Type: character vector |
Values: non-zero integer |
Default:
'2' |
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
To generate PLC code for a model that uses a Data Store Memory
block, first define a Simulink.Signal
in the base
workspace. Then in the Signal Attributes tab of the block
parameters, set the data store name to resolve to that of the Simulink.Signal
object.
Data Store Read | Data Store Write