You can log the values of a local or global data store data variable for all the steps in a simulation. Two common uses of data store logging are for:
Model debugging – view the order of all data store writes
Confirming a model modification – use the logged data to establish a baseline for comparing results to identify the impact of a model modification
For an example of logging a global data store, see Using Data Stores Across Multiple Models.
You can log data stores that use the following data types:
All built-in data types
Enumerated data types
Fixed-point data types
You can log data stores that use any dimension level or complexity.
Limitations for using data store logging in a model are:
To log data for a data store memory:
Simulate the top-level model in Normal mode.
For local data stores, the model containing the Data Store Memory block must be in Model Reference Normal mode.
Any block in a referenced model that writes to the data store memory must be executed in model reference Normal mode.
You cannot log data stores that use custom data types, including buses.
To log a local data store that you create with a Data Store Memory block:
In the model, open the Model Data Editor. In the Modeling tab, click Model Data Editor.
On the Data Stores tab, set the Change
view drop-down list to
Instrumentation
.
In the data table, for the target data store, select the check box in the Log Data column.
If the target data store does not appear in the table, click the Change scope button to display data stores that are defined in subsystems below your current system.
Optionally, to configure additional logging characteristics such as the maximum number of data points to log, open the Property Inspector (in the Modeling tab, under Design, click Property Inspector). Use the Property Inspector to open the block dialog box and inspect the Logging tab.
Enable data store logging with the Model Configuration Parameters > Data Import/Export > Data stores parameter.
Simulate the model.
When you enable logging for a model, and you configure a local data store for logging, the Data Store Memory block displays a blue icon. If you do not enable logging for the model, then the icon is gray.
Simulink.Signal
ObjectYou can create local and global data stores using a Simulink.Signal
object.
See Data Stores with Signal Objects for details.
To log a data store that you create with a Simulink.Signal
object:
Create a Simulink.Signal
object in a workspace that is visible to every
component that needs to access the data store, as described in Data Stores with Signal Objects.
Use the name of the Simulink.Signal
object in the Data store
name block parameters of the Data Store Read and Data Store
Write blocks that you want to write to and read from the data store.
From the MATLAB® command line, set DataLogging
(which is a
property of the LoggingInfo
property of
Simulink.Signal
) to 1
.
For example, if you use a Simulink.Signal
object called
DataStoreSignalObject
to create a data store, use the
following command:
DataStoreSignalObject.LoggingInfo.DataLogging = 1
Optionally, specify limits for the amount of data logged, using the following properties,
which are properties of the LoggingInfo
property of the
Simulink.Signal
object: Decimation
,
LimitDataPoints
, and
MaxPoints
.
Enable data store logging with the Model Configuration Parameters > Data Import/Export > Data stores parameter.
Simulate the model.
The following Simulink® classes represent data from data store logging and provide methods for accessing that data:
Class | Description |
---|---|
Simulink.SimulationData.BlockPath | Represents a fully specified Simulink block path; use for capturing the full model reference hierarchy |
Simulink.SimulationData.Dataset | Stores logged data elements and provides searching capabilities;
use to group Simulink.SimulationData.Element objects
in a single object |
Simulink.SimulationData.DataStoreMemory | Stores logging information from a data store during simulation |
You can also convert data logged in formats other than Dataset. For more information, see Dataset Conversion for Logged Data.
To view data store logging data from the command line, view
the output data set in the base workspace. The default variable for
the data store logging data set is dsmout
.
The sldemo_mdlref_dsm model illustrates approaches for viewing data store logging data.
To find an element in the data store logging data, based on
the Name
or BlockType
property,
use the getElement
method of Simulink.SimulationData.Dataset
.
For example:
dsmout.getElement('RefSignalVal') ans = Simulink.SimulationData.DataStoreMemory Package: Simulink.SimulationData Properties: Name: 'RefSignalVal' Blockpath: [1x1 Simulink.SimulationData.BlockPath] Scope: 'local' DSMWriterBlockPaths: [1x2 Simulinkl.SimulationData.BlockPath] DSMWriters: [101x1 uint32] Values: [101x1 timeseries]
To access an element by index, use the Simulink.SimulationData.Dataset.getElement
method.
Simulink.SimulationData.BlockPath
| Simulink.SimulationData.Dataset
| Simulink.SimulationData.DataStoreMemory