Contenuto principale

matlab.io.datastore.sdidatastore

R2026b

Datastore for Simulation Data Inspector signals

Description

A matlab.io.datastore.sdidatastore object provides access to signals logged to the Simulation Data Inspector that are too large to fit into memory. An sdidatastore object references the data for a single signal. The read function loads the signal data referenced by an sdidatastore object in a chunk-wise manner such that each chunk always fits into memory. You can use an sdidatastore object to create a tall timetable for your signal data. For more information about working with tall arrays, see Tall Arrays.

Note

matlab.io.datastore.sdidatastore objects do not support parallel computations. If you have a Parallel Computing Toolbox™ license, use mapreducer(0) to set the execution environment to the local MATLAB® client before creating a tall timetable from a matlab.io.datastore.sdidatastore object.

Creation

Description

sigObj = getAsDatastore(dsrObj,arg) creates an sdidatastore object in the Values property of the returned Simulink.SimulationData.Signal object sigObj for the signal specified by the search criterion arg in the Simulation Data Inspector run referenced by the Simulink.sdi.DatasetRef object dsrObj. Use the search criterion arg to specify a signal by index or by name.

example

ds = matlab.io.datastore.sdidatastore(signalID) creates the sdidatastore object ds for the signal corresponding to the specified signalID.

example

Input Arguments

expand all

Search criterion used to retrieve the signal in the Simulation Data Inspector run referenced by the Simulink.sdi.DatasetRef object, specified as one of these values:

  • Positive integer — For index-based searches, specify arg as a positive integer representing the index of the desired signal.

  • String or character vector — For name-based searches, specify arg as a string or character vector containing the name of the desired signal.

Example: "MySignal"

Example: 3

Numeric signal identifier, specified as a positive integer. The Simulation Data Inspector assigns a signal ID to each signal when a run is created. You can get the signal ID for a signal using one of these functions:

Properties

expand all

Signal name specified as a character vector.

Example: 'My Signal'

Referenced signal object associated with the sdidatastore object, specified as a Simulink.sdi.Signal object. The Signal property provides access to the Signal object data and metadata.

Object Functions

hasdata Determine whether data is available to read
resetReset datastore to initial position
readallRead all data in datastore
readRead chunk of data in datastore
preview Return subset of data from datastore

Examples

collapse all

To create a run of logged signals, simulate the model ThreeSigs.

mdl = "ThreeSigs";
out = sim(mdl);

Get the latest run.

runObj = Simulink.sdi.Run.getLatest;

Create a Simulink.sdi.DatasetRef object that references the Simulation Data Inspector run.

dsRef = getDatasetRef(runObj);

Get the names of the elements in the DatasetRef object.

dsRefNames = getElementNames(dsRef)
dsRefNames = 3×1 cell
    {'sineSig' }
    {'randSig' }
    {'chirpSig'}

Get an sdidatastore object for the sineSig signal. The sdidatastore object is stored in the Values property of the returned Simulink.SimulationData.Signal object.

[sigObj,name,idx] = getAsDatastore(dsRef,"sineSig")
sigObj = 
  Simulink.SimulationData.Signal
  Package: Simulink.SimulationData

  Properties:
              Name: 'sineSig'
    PropagatedName: ''
         BlockPath: [1×1 Simulink.SimulationData.BlockPath]
          PortType: 'inport'
         PortIndex: 1
            Values: [1×1 matlab.io.datastore.sdidatastore]


  Methods, Superclasses
name = 
'sineSig'
idx = 
1

Suppose you want to create a tall timetable for a signal in the Simulation Data Inspector repository. You can create a tall timetable for a signal in the Simulation Data Inspector repository using a Simulink.sdi.Signal object or by first creating a matlab.io.datastore.sdidatastore object for the signal. Generally, tall timetables are backed by datastores. You can use a matlab.io.datastore.sdidatastore object to incrementally read and process signal data for signals that do not fit into memory. A tall timetable handles the data chunking and processing in the background. In general, you can work with tall timetables very similarly to how you work with in-memory data.

Get the signal ID for a signal in the run and create an sdidatastore object to reference the data. For example, reference the data in the first signal logged in the latest run.

lastestRunObj = Simulink.sdi.Run.getLatest;
sigID = getSignalIDByIndex(latestRunObj,1);
dstore = matlab.io.datastore.sdidatastore(sigID);

Create a tall timetable from the sdidatastore object. Create a tall timetable from the matlab.io.datastore.sdidatastore object to use for processing the signal data. When you have a Parallel Computing Toolbox license, you need to explicitly set the execution environment to the local MATLAB session using mapreducer before creating the tall timetable. The matlab.io.datastore.sdidatastore object does not support parallel computations.

mapreducer(0);
tt = tall(dstore)
tt =

  M×1 tall timetable

         Time          Data 
    ______________    ______

    0 sec             1.2855
    0.00056195 sec    1.2855
    0.0033717 sec     1.2855
    0.01 sec          1.2398
    0.02 sec           1.199
    0.03 sec          1.1628
    0.04 sec          1.1309
    0.043098 sec      1.1309
          :             :
          :             :

A matlab.io.datastore.sdidatastore object references signal data in the Simulation Data Inspector repository. When the signal is too large to fit into memory, you can use the sdidatastore object to incrementally process the data manually or to create a tall timetable for the signal that handles the incremental processing for you.

Create sdidatastore for Signal

Simulate the ThreeSigs model, which is configured to log three signals, to create data in the Simulation Data Inspector repository.

mdl = "ThreeSigs";
out = sim(mdl);

The model is configured to log data using a single Simulink.SimulationOutput object named out. The SimulationOutput object contains the logged output data in a Simulink.SimulationData.Dataset object named yout. Use dot notation to access the logged data.

out.yout
ans = 
Simulink.SimulationData.Dataset 'yout' with 3 elements

                         Name      BlockPath      
                         ________  ______________ 
    1  [1x1 Signal]      sineSig   ThreeSigs/Out1
    2  [1x1 Signal]      randSig   ThreeSigs/Out2
    3  [1x1 Signal]      chirpSig  ThreeSigs/Out3

  - Use braces { } to access, modify, or add elements using index.

Get the signal ID for the signal named sineSig.

runCount = Simulink.sdi.getRunCount;
latestRunID = Simulink.sdi.getRunIDByIndex(runCount);
latestRun = Simulink.sdi.getRun(latestRunID);
sineSigID = getSignalIDsByName(latestRun,"sineSig");

Use the signal ID to create an sdidatastore object for the sineSig signal.

sineSDIds = matlab.io.datastore.sdidatastore(sineSigID);

Verify Contents of Datastore

Check the Name property of the sdidatastore object to verify that it matches your expectations.

sineSDIds.Name
ans = 
'sineSig'

You can also use the preview function to verify the first ten samples in the signal.

preview(sineSDIds)
ans = 10×1 timetable
     Time        Data  
    _______    ________

    0 sec             0
    0.1 sec    0.099833
    0.2 sec     0.19867
    0.3 sec     0.29552
    0.4 sec     0.38942
    0.5 sec     0.47943
    0.6 sec     0.56464
    0.7 sec     0.64422
    0.8 sec     0.71736
    0.9 sec     0.78333

Process Signal Data with sdidatastore Object

When your signal is too large to fit into memory, use read to load and incrementally process data from the Simulation Data Inspector repository in chunks. Use hasdata as the condition for a while loop to incrementally process the whole signal. For example, find the maximum signal value.

latestMax = [];

while hasdata(sineSDIds)
    sineChunk = read(sineSDIds);
    sineChunkData = sineChunk.Data;
    latestMax = max([sineChunkData; latestMax]);
end

latestMax
latestMax = 
0.9996

On each read operation, the read function updates the read position for the start of the next read operation. After reading some or all of the sdidatastore object, you can reset the read position to start again from the beginning of the signal.

reset(sineSDIds)

Process Signal Data in Memory

When the signal referenced by your sdidatastore object fits into memory, you can use the readall function to read all the signal data into memory for processing. The readall function returns a timetable with all the signal data.

sineTimetable = readall(sineSDIds);
sineMax = max(sineTimetable.Data)
sineMax = 
0.9996

Version History

Introduced in R2017b