Simulink.DataStore
R2026bDescription
Use a Simulink.DataStore object to represent a data store memory
at the root level of a model. This object must be defined in the model workspace. Any
Data Store Read block or Data Store Write block can access
this data store if the block is located at the same hierarchical level as, or below, the data
store object.
Creation
To create a Simulink.DataStore object:
Use the Model Explorer. For more information, see Use Simulink.DataStore Objects to Specify Data Store Using Model Explorer.
Use the
Simulink.DataStorefunction.
Syntax
Description
dataStoreObj = Simulink.DataStore returns a
Simulink.DataStore object with default property values.
dataStoreObj = Simulink.DataStore(signalObj) returns a
Simulink.DataStore object with the property values of the data store
object set to the property values of the Simulink.Signal object indicated
by signalObj.
dataStoreObj = Simulink.DataStore(dsmBlkHandle) returns a
Simulink.DataStore object with the property values of the data store
object set to the parameter values of a Data Store Memory block, where
dsmBlkHandle indicates the block handle. To obtain the block handle
for a block, use the getSimulinkBlockHandle function.
dsmBlkHandle = getSimulinkBlockHandle('ModelName/dsmBlk',true)Properties
Option to access the memory defined at a higher level in the model hierarchy,
specified as a numeric or logical 1 (true) or 0
(false).
When you set this value to 1, a subset of Simulink® blocks can access the elements of the DataStore object
defined at a higher level in the model hierarchy. These blocks include the Data
Store Read block, Data Store Write block, S-Function block, MATLAB Function block, MATLAB System block, and Chart (Stateflow) block. For more information, see Access Data Store at Higher Level in Model Hierarchy.
Example:
dataStoreObj.DataStoreReference = 1
Limitations
When you set the DataStoreReference property value to
1, these signal values are not supported:
'auto'forDataType'auto'forComplexity'-1'forDimensions
You must specify explicit values for these properties.
Data Types: logical
Option to allow multiple Model blocks to read from and write to the
same data store, specified as a numeric or logical 1(true) or
0(false).
In a single model reference hierarchy, when you use multiple Model
blocks to refer to a model that contains a DataStore object, 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 set the
ShareAcrossModelInstances property value to 1,
instead of interacting with separate copies, all 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. 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 more information, see Share Data Among Referenced Model Instances.
Example:
dataStoreObj.ShareAcrossModelInstances = 1
Data Types: logical
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.
Example: dataStoreObj.TreatVectorAs1D = 0
Data Types: logical
Diagnostic actions for the data store object, specified as none,
warning, or error. The diagnostic options help
Simulink to detect the sequence of read and write actions for a data store
object.
Use the Diagnostics property to create a
DataStoreDiagnostics object to specify diagnostic actions for
Simulink.DataStore objects.
The diagnostic options are:
Detect Read Before Write — Select this diagnostic action if the model attempts to read data from a data store to which it has not written data in this time step.
none— This option is the default. This option does not produce any response.warning— This option displays a warning and continues the simulation.error— This option terminates the simulation and displays an error.
Detect Write After Read — Select this diagnostic action if the model attempts to write data to the data store after previously reading data from it in the current time step.
none— This option is the default. This option does not produce any response.warning— This option displays a warning and continues the simulation.error— This option terminates the simulation and displays an error.
Detect Write After Write — Select this diagnostic action if the model attempts to write data to the data store twice in succession in the current time step.
none— This option does not produce any response.warning— This option is the default. This option displays a warning and continues the simulation.error— This option terminates the simulation and displays an error.
Example: dataStoreObj.Diagnostics.DetectReadBeforeWrite =
'warning'
Data Types: char | string
Dimensions of the data store, specified as a scalar, a vector, an array, or a matrix.
The default value, -1, enables you to set the dimensions of the
data store by using the InitialValue property. 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 InitialValue property, 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.
Example: dataStoreObj.Dimensions = 8
Example: dataStoreObj.Dimensions = [1
myDataStoreDim]
Data Types: double
Initial value of the data store object, specified as a character vector or a string scalar.
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 Dimensions 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 object 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 Elements.
For enumerated data types, the initial value must be a member of the enumerated
class. Suppose, you have an enum class, TrafficLightColors, with
three members: Red, Yellow, and
Green. To specify Green as the initial value,
set InitialValue to
TrafficLightColors.Green.
Example:
dataStoreObj.InitialValue = '5'
Data Types: char | string
Complexity of the data store signal, specified as real or complex.
Example: dataStoreObj.Complexity = 'complex'
Data Types: char | string
Data store signal logging settings, returned as a
Simulink.LoggingInfo object with its default property values. To
learn more about how to override these values, see Simulink.SimulationData.LoggingInfo.
Data Types: int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string
Description of the data store object, returned as a character vector or string scalar.
This property is used by the Simulink Report Generator and for code generation.
If you have an Embedded Coder® license, you can add the data store description as a comment for the variable declaration in generated code:
Specify a storage class for the signal object other than
'Auto'.On the Code Generation > Comments pane of the model Configuration Parameters dialog box, select the model configuration parameter Simulink data object descriptions. For more information, see Simulink data object descriptions (Embedded Coder).
Example: dataStoreObj.Description = 'This data store contains a reusable
algorithm'
Data Types: char | string
Output signal data type, specified as one of these values:
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.NumericTypeobject).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: <object name>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.
Example: dataStoreObj.DataType = 'double'
Data Types: char | string
Minimum value of the output signal associated with the data store object, specified
as an empty array ([]) or real double scalar. 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 object, do not set the
minimum value for bus data on the object. 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 Min 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).
Example: dataStoreObj.Min = -8
Data Types: double
Maximum value of the output signal associated with the data store object, specified
as an empty array ([]) or real double scalar. 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 object, do not set the
maximum value for bus data on the object. 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).
Example: dataStoreObj.Max = 8
Data Types: double
Examples
Create a data store object A inside a model named
mdlName. Replace
mdlName with the name of your model for your
application.
Load the model.
load_system("mdlName.slx")Create a data store object named A and add a description.
A = Simulink.DataStore;
A.Description = 'Nonvolatile memory that stores state values during simulation.';Configure the data store object to access memory that is defined at a higher level in the model hierarchy.
A.DataStoreReference = 1;
Configure the signal associated with the data store object. To configure the signal, change the signal attributes according to your modeling requirements.
A.DataType = 'double'; A.Complexity = 'real'; A.Dimensions = [1 1]; A.InitialValue = '5'; A.Min = -7; A.Max = 7;
Set up diagnostic checks.
A.Diagnostics.DetectReadBeforeWrite = 'warning'; A.Diagnostics.DetectWriteAfterRead = 'error'; A.Diagnostics.DetectWriteAfterWrite = 'none';
Set up how the data store logs data.
A.LoggingInfo.DataLogging = 1;
A.LoggingInfo.LoggingName = 'State value';
A.LoggingInfo.DecimateData = 1;
A.LoggingInfo.Decimation = 3;
A.LoggingInfo.LimitDataPoints = 1;
A.LoggingInfo.MaxPoints = 4000;To specify these settings in the model workspace, use the assignin function.
In the MATLAB Command Window, enter these commands.
mdlWks = get_param(mdlName, 'ModelWorkspace'); assignin(mdlWks,'A',A);
Alternatively, to specify the settings using the Model Explorer, follow these steps.
On the Modeling tab, click Model Explorer.
In the Model Hierarchy pane, from the model (
modelName.slx) hierarchy tree, right-click Model Workspace node.Select the Properties menu item, which opens the Model Workspace dialog box. To load the settings, take one of these actions:
Save the configuration settings in a MATLAB (
.m) file and load the file by setting Data source toMATLAB File.Specify these settings directly as MATLAB code by setting Data source to
MATLAB Code.
Create a data store object from a Data Store Memory
block. This example uses the Data Store Memory block named
AAA from DataStoreMemoryBot.slx model in Access Data Store at Higher Level in Model Hierarchy. The Data
Store Memory block has these properties:
Data store name is set as
AAA.Data store reference is selected.
Initial value is set to its default value of
0.Data type is
int32.Dimensions is
[1 1].Signal type is
real.
Get the block handle for the Data Store Memory block
AAA.
blkHandle = getSimulinkBlockHandle('DataStoreMemoryBot/Data Store Memory',true);Create a data store object named dsobjAAA using the Data
Store Memory block
handle.
dsobjAAA = Simulink.DataStore(blkHandle);
To specify these settings in the model workspace, use the assignin function.
In the MATLAB Command Window, enter these commands.
mdlWks = get_param(mdlName, 'ModelWorkspace'); assignin(mdlWks,'dsobjAAA',dsobjAAA);
Alternatively, to specify the settings by using the Model Explorer, follow these steps.
On the Modeling tab, click Model Explorer.
In the Model Hierarchy pane, from the model (
modelName.slx) hierarchy tree, right-click Model Workspace.Select Properties, which opens the Model Workspace dialog box. To load the settings, take one of these actions:
Save the configuration settings in a MATLAB (
.m) file and load the file by setting Data source toMATLAB File.Specify these settings directly as MATLAB code by setting Data source to
MATLAB Code.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced in R2026b
See Also
Blocks
Objects
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.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)