Main Content

Log Data Stores

Logging Local and Global Data Store Values

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:

  • 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 Use Data Stores Across Multiple Models.

Supported Data Types, Dimensions, and Complexity for Logging Data Stores

You can log data stores that use these types:

  • All built-in data types

  • Enumerated data types

  • Fixed-point data types

You can log data stores that use any dimension or complexity.

Data Store Logging Limitations

Limitations for using data store logging in a model include:

  • To log data for a Data Store Memory block:

    • Before R2024b: Simulate the top-level model in Normal mode.

    • Before R2024b: For local data stores, the model containing the Data Store Memory block must simulate in normal mode.

    • Before R2024b: Any block in a referenced model that writes to the data store memory must simulate in normal mode.

  • You cannot log data stores that use custom data types, including buses.

Note

You can log data stores in accelerator and rapid accelerator mode simulations. (since R2024b)

Logging Data Stores Created with Data Store Memory Block

To log a local data store that you create with a Data Store Memory block:

  1. Double-click the Data Store Memory block to open the open the Block Parameters dialog box.

  2. In the Logging tab, select Log data store data.

  3. Optionally, you can configure additional logging characteristics such as the logging name or the maximum number of data points to log.

  4. To enable data store logging, select Model Configuration Parameters > Data Import/Export > Data stores.

  5. Simulate the model.

Logging Icon for Data Store Memory Block

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.

Logging Data Stores Created with Simulink.Signal Object

You can create local and global data stores using a Simulink.Signal object. For more information, see Data Stores with Signal Objects.

To log a data store that you create with a Simulink.Signal object:

  1. 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.

  2. 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, respectively.

  3. 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 this command.

    DataStoreSignalObject.LoggingInfo.DataLogging = 1
  4. 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.

  5. Select Model Configuration Parameters > Data Import/Export > Data stores to enable data store logging.

  6. Simulate the model.

Accessing Data Store Logging Data

The table lists Simulink® objects that represent data from data store logging and provide methods for accessing that data.

ObjectDescription
Simulink.SimulationData.BlockPathRepresents a fully specified Simulink block path. Use a BlockPath object for capturing the full model reference hierarchy.
Simulink.SimulationData.DatasetStores logged data elements and provides searching capabilities. Use a Dataset object to group other element objects in a single object.
Simulink.SimulationData.DataStoreMemoryStores logging information from a data store during simulation.

You can also convert data logged in formats other than Dataset. For more information, see Convert Data to Dataset Format.

View Data Store Data

By default, all simulation data logged to the workspace is returned as a single Simulink.SimulationOutput object in a variable with the default name out. The SimulationOutput object contains complete simulation metadata and all simulation data logged to the workspace.

When you configure a model to return all simulation data in a single SimulationOutput object, signal logging data is stored as a property of the SimulationOutput object in a Simulink.SimulationData.Dataset object with the default variable name dsmout. When a model is not configured to return a single simulation output, signal logging data is returned to the workspace in a Dataset object with the default variable name dsmout. For more information, see Use Data Stores Across Multiple Models.

Accessing Elements in Data Store Logging Data

To find an element in the logged data store based by name or index, use the get function. For example, you can find the logged data store named RefSignalVal.

get(out.dsmout,"RefSignalVal")
ans = 

  Simulink.SimulationData.DataStoreMemory
  Package: Simulink.SimulationData

  Properties:
                   Name: 'RefSignalVal'
              BlockPath: [1×1 Simulink.SimulationData.BlockPath]
                  Scope: 'local'
    DSMWriterBlockPaths: [1×1 Simulink.SimulationData.BlockPath]
             DSMWriters: [1101369×1 uint32]
                 Values: [1×1 timeseries]


  Methods, Superclasses

To access a data store element by index, you can use curly braces to streamline the indexing syntax. The index must be a positive integer that is not greater than the number of elements in the variable. For example, get the second element of the dsmout dataset.

out.dsmout{2}

See Also

| |

Related Topics