Data Store Memory
Define data store
- Library:
Simulink / Signal Routing
Description
TheData Store Memoryblock defines and initializes a named shared data store, which is a memory region usable byData Store ReadandData Store Writeblocks that specify the same data store name.
The location of theData Store Memoryblock that defines a data store determines whichData Store ReadandData Store Writeblocks can access the data store:
If theData Store Memoryblock is in thetop-level system,Data Store ReadandData Store Writeblocks anywhere in the model can access the data store.
If theData Store Memoryblock is in asubsystem,Data Store ReadandData Store Writeblocks in the same subsystem or in any subsystem below it in the model hierarchy can access the data store.
Data Store ReadorData Store Writeblocks cannot access aData Store Memoryblock that is either in a model that contains aModelblock or in a referenced model.
Do not include aData Store Memoryblock 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 useSimulink.Signal
objects in addition to, or instead of,Data Store Memoryblocks to define data stores. A data store defined in thebaseworkspace with a signal object is aglobaldata store. Global data stores are accessible to every model, including all referenced models. See数据存储for more information.
You can select aData Store Read,Data Store Write, orData Store Memoryblock to highlight blocks related to it. To show a related block in an open diagram or new tab, pause on the ellipsis that appears after selection. Then, selectRelated Blocksfrom the action bar. When multiple blocks correspond to the selected block, a list of related blocks opens. You can filter the list of related blocks by entering a search term in the text box. After you select a related block from the list, window focus goes to the open diagram or new tab that shows the related block.
Parameters
Main
Data store name
— Name for the data store
A
(default) | character vector | string
Specify a name for the data store you are defining with this block.Data Store ReadandData Store Writeblocks with the same name can read from, and write to, the data store initialized by this block. The name can represent aData Store Memoryblock or a sign object defined to be a data store.
Programmatic Use
Block Parameter:DataStoreName |
Type: character vector |
Values:'A' | ... |
Default:'A' |
Rename All
— Rename this data store throughout the model
button
Rename this data store everywhere theData Store ReadandData Store Writeblocks use it in a model.
Limitations
You cannot useRename Allto rename a data store if you:
Use a
Simulink.Signal
object in a workspace to control the code generated for the data storeUse a
Simulink.Signal
object instead of aData Store Memoryblock to define the data store
You must instead rename the correspondingSimulink.Signal
object from Model Explorer. For an example, seeRename Data Store Defined by Signal Object.
Corresponding Data Store Read/Write blocks
— Path to connected Data Store Read/Write blocks
block path
List all theData Store ReadandData Store Writeblocks 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.
Signal Attributes
Initial value
— Initial value of data store
0
(default) | scalar | vector | matrix | N-D array
Specify the initial value or values of the data store. TheMinimumparameter specifies the minimum value for this parameter, and theMaximum参数指定的最大价值。
If you specify a nonscalar value and setDimensionsto-1
(the default), the data store has the same dimensions as the array. Data that you write to the data store (by usingData Store Writeblocks) must have these dimensions.
If you set theDimensionsparameter to a value other than-1
,e 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 parameterUnderspecified initialization detectiontoSimplified
. For more information about initializing nonvirtual bus signals using structures, seeSpecify Initial Conditions for Bus Elements.
Programmatic Use
Block Parameter:InitialValue |
Type: character vector |
Values: scalar | vector | matrix | N-D array |
Default:'0' |
Minimum
——最小输出值范围检查ing
[]
(default) | scalar
Specify 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, seeSimulink.BusElement
.
金宝app®uses the minimum value to perform:
Parameter range checking (seeSpecify Minimum and Maximum Values for Block Parameters).
Simulation range checking (seeSpecify Signal Ranges).
Automatic scaling of fixed-point data types.
从th优化你的代码生成e model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, seeOptimize using the specified minimum and maximum values(Embedded Coder).
Programmatic Use
Block Parameter:OutMin |
Type: character vector |
Values: scalar |
Default:'[ ]' |
Maximum
— Maximum output value for range checking
[]
(default) | scalar
Specify 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, seeSimulink.BusElement
.
Simulink uses the maximum value to perform:
Parameter range checking (seeSpecify Minimum and Maximum Values for Block Parameters).
Simulation range checking (seeSpecify Signal Ranges).
Automatic scaling of fixed-point data types.
从th优化你的代码生成e model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, seeOptimize using the specified minimum and maximum values(Embedded Coder).
Programmatic Use
Block Parameter:OutMax |
Type: character vector |
Values: scalar |
Default:'[ ]' |
Data type
— Output data type
Inherit: auto
(default) |double
|单
|half
|int8
|uint8
|int16
|uint16
|int32
|uint32
|int64
|uint64
|boolean
|fixdt(1,16,0)
|fixdt(1,16,2^0,0)
|string
|Enum:
|Simulink.ImageType(480,640,3)
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,
单
).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; useBus:
to specify a bus data type.If you have Computer Vision Toolbox™, use the constructor for the
Simulink.ImageType
(Computer Vision Toolbox)object and specify the properties to describe the image. By default, the data type uses theSimulink.ImageType(480,640,3)
expression that represents the rows, columns, and channels of the image respectively.
Click theShow data type assistantbuttonto display theData Type Assistant, which helps you set the data type attributes. For more information, seeSpecify Data Types Using Data Type Assistant.
Programmatic Use
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: |
Default:'Inherit: auto' |
Lock output data type setting against changes by the fixed-point tools
— Prevent fixed-point tools from overriding Output data type
off
(default) |on
Select this parameter to prevent the fixed-point tools from overriding theOutputdata type you specify on the block. For more information, seeUse Lock Output Data Type Setting(Fixed-Point Designer).
Programmatic Use
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 | matrix
Dimensions of the data store. The default value,-1
,使您能够设置dimensions of the data store by using theInitial valueparameter. 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 theInitial valueparameter, 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.
Programmatic Use
Block Parameter:Dimensions |
Type:character vector |
Values:scalar | vector | matrix |
Default:'-1' |
Interpret vector parameters as 1-D
— Interpret vectors as 1-D
on
(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]
,e data store stores a one-dimensional vector with three elements.
For more information, seeDetermine the Output Dimensions of Source Blocks.
Programmatic Use
Block Parameter:VectorParams1D |
Type: character vector |
Values:'off' | 'on' |
Default:'on' |
Signal type
— Complexity of data store values
auto
(default) |real
|complex
Specify the numeric type, real or complex, of the values in the data store.
Programmatic Use
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 store
off
(default) |on
In a single model reference hierarchy, when you use multipleModelblocks to refer to a model that contains aData Store Memoryblock, by default, each instance of the referenced model (eachModelblock) reads from and writes to a separate copy of the data store. When you selectShare 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 parameterCode interface packagingtoReusable function
to generate reentrant code from a model (Simulink Coder™), a data store withShare across model instancesselected 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, seeShare Data Store Between Instances of a Reusable Algorithm. For more information, seeShare Data Among Referenced Model Instances.
Programmatic Use
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 object
off
(default) |on
Specify that Simulink software, when compiling the model, searches the model and base workspace for aSimulink.Signal
object having the same name, as described inSymbol 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.
Programmatic Use
Block Parameter:StateMustResolveToSignalObject |
Type:character vector |
Values:'off' | 'on' |
Default:'off' |
Diagnostics
Detect Read Before Write
— Action when model attempts to read data before writing in current time step
warning
(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 theDetect read before writediagnostic in theData Store Memory blocksection of theModel Configuration Parameters>Diagnostics>Data Validitypane.
None
— Produce no response.Warning
— Display a warning and continue the simulation.Error
— Terminate the simulation and display an error.
Programmatic Use
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 step
warning
(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 theDetect write after readdiagnostic in theData Store Memory blocksection of theModel Configuration Parameters>Diagnostics>Data Validitypane.
None
— Produce no response.Warning
— Display a warning and continue the simulation.Error
— Terminate the simulation and display an error.
Programmatic Use
Block Parameter:WriteAfterReadMsg |
Type:character vector |
Values:'none' | 'warning' | 'error' |
Default:'warning' |
Detect Write After Write
— Action when model writes twice in same time step
warning
(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 theDetect write after writediagnostic in theData Store Memory blocksection of theModel Configuration Parameters>Diagnostics>Data Validitypane.
None
— Produce no response.Warning
— Display a warning and continue the simulation.Error
— Terminate the simulation and display an error.
Programmatic Use
Block Parameter:WriteAfterWriteMsg |
Type:character vector |
Values:'none' | 'warning' | 'error' |
Default:'warning' |
Logging
Log data store data
— Log data store data
off
(default) |on
Select this option to save the values of this signal to the MATLAB workspace during simulation. SeeSignal Loggingfor details.
Programmatic Use
Block Parameter:DataLogging |
Type:character vector |
Values:'off' | 'on' |
Default:'off' |
Logging name
— Name associated with logged signal data
Use 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, selectCustom
from the list box and enter the custom name in the adjacent edit field.
Programmatic Use
Block Parameter:DataLoggingNameMode |
Type:character vector |
Values:'SignalName' | 'Custom' |
Default:'' |
Note
If you setDataLoggingNameMode
toCustom
, you must specify the name associated with logged signal data using theDataLoggingName
parameter.
Block Parameter:DataLoggingName |
Type:character vector |
Values:character vector |
Default:'' |
Limit data points to last
— Discard all but the last N data points
5000
| non-zero integer
Discard all but the lastN
data points, whereN
is the number that you enter in the adjacent edit field. For more information, seeLog Data Stores.
Programmatic Use
Block Parameter:DataLoggingMaxPoints |
Type:character vector |
Values:nonzero integer |
Default:'5000' |
Decimation
— Log every Nth data point
2
(default) | integer
Log everyN
th data point, whereN
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 of0.1
s. If you select this option and accept the default decimation value (2
), Simulink records data points for this signal at times0.0
,0.2
,0.4
, and so on. For more information, seeLog Data Stores.
Programmatic Use
Block Parameter:DataLoggingLimitDataPoints |
Type:character vector |
Values:non-zero integer |
Default:'2' |
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.
To generate PLC code for a model that uses aData Store Memoryblock, first define aSimulink.Signal
in the base workspace. Then in theSignal Attributestab of the block parameters, set the data store name to resolve to that of theSimulink.Signal
object.
Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.
Version History
See Also
Data Store Read|Data Store Write
Topics
- Storing Data Using Data Store Memory Blocks
- 数据存储
- Choosing How to Store Global Data
- C Code Generation Configuration for Model Interface Elements(Simulink Coder)
- Organize Parameter Data into a Structure by Using Struct Storage Class(Embedded Coder)
- Access Data Stores with Simulink Blocks
- Log Data Stores
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择一个网站
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)