Main Content

getAsDatastore

Get matlab.io.datastore.SimulationDatastore representation of element from referenced Dataset object

Description

element = getAsDatastore(dsr,idx) returns a matlab.io.datastore.SimulationDatastore representation of an element from the Simulink.SimulationData.DatasetRef object dsr based on the index idx.

You can get a SimulationDatastore representation of a Dataset element if the element was placed into the MAT-file by:

  • Logging Dataset format data to persistent storage

  • Placing the element into a Simulink.SimulationData.Dataset object and saving the Dataset object to a Version 7.3 MAT-file

Note

You cannot create a SimulationDatastore representation for Dataset elements that contain array data.

You can use SimulationDatastore objects to:

  • Refer to logged simulation data that is stored on disk in a MAT-file.

  • Specify signals to stream incrementally from disk to a simulation.

  • Provide a basis for big data analysis using MATLAB® functions.

example

element = getAsDatastore(dsr,elName) returns a SimulationDatastore representation of an element or collection of elements from the referenced Dataset object based on the element name elName.

element = getAsDatastore(dsr,bp) returns a SimulationDatastore representation of an element or collection of elements from the referenced Dataset object based on the block path bp.

Examples

collapse all

Open the SineWave model, which contains a Sine Wave block connected to an Outport block.

mdl = "SineWave";
open_system(mdl)

The SineWave model

Configure the model to log output data to persistent storage and simulate a model.

  1. In the Configuration Parameters > Data Import/Export pane, select Log Dataset data to file. Then, click OK.

  2. Click Run to simulate the model.

Alternatively, you can configure the model to log Dataset data to a file and simulate the model programmatically. By default, the data is saved to a MAT-file named out.mat.

sim(mdl,"LoggingToFile","on");

Create a DatasetRef object for the logged output data from the SineWave model.

sigLogRef = Simulink.SimulationData.DatasetRef("out.mat","yout");

Use the getAsDatastore function to create a SimulationDatastore object for the sineSig signal. The SimulationDatastore object exists in the Values property of the returned Simulink.SimulationData.Signal object.

sineSig_dst = getAsDatastore(sigLogRef,"sineSig")
sineSig_dst = 
  Simulink.SimulationData.Signal
  Package: Simulink.SimulationData

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

The model MultByTwo contains a Gain block that multiplies input data by 2 and logs the data using an Outport block.

The MultByTwo model

Load the data referenced from the SineWave model into the MultByTwo model. Because the Values property of the sineSig_dst Signal object is a SimulationDatastore object, the signal data streams into your model.

mdl2 = "MultByTwo";
open_system(mdl2)
multByTwoOut = sim(mdl2,"LoadExternalInput","on","ExternalInput","sineSig_dst");

The Dashboard Scope block in the MultByTwo model shows that the input streamed from the SineWave model is a sine wave with an amplitude of 1, and the output is a sine wave with an amplitude of 2.

The Dashboard Scope block plot

Input Arguments

collapse all

Reference to a Dataset object stored in a MAT-file, specified as a Simulink.SimulationData.DatasetRef object.

Index of DatasetRef object element to get as SimulationDatastore representation, specified as a positive integer.

Name of DatasetRef object element to get as SimulationDatastore representation, specified as a string or character vector.

Block path of DatasetRef object element to get as SimulationDatastore representation, specified as a Simulink.BlockPath object or Simulink.SimulationData.BlockPath object.

Output Arguments

collapse all

SimulationDatastore representation of element from referenced Dataset object, specified as a matlab.io.datastore.SimulationDatastore object or Simulink.SimulationData.Signal, Simulink.SimulationData.State, or similar object whose Values parameter contains a matlab.io.datastore.SimulationDatastore object.

Alternative

You can use curly braces to streamline the indexing syntax to obtain a SimulationDatastore object for DatasetRef object signal values instead of using the getAsDatastore function. The requirements and results are the same when using curly braces as when using the getAsDatastore function. For example, suppose you configure a model to log signal data to persistent storage by selecting the Log Dataset data to file configuration parameter and simulate that model. You can use curly braces to get a SimulationDatastore object for the first element in the referenced Dataset object. The SimulationDatastore object exists in the Values property of the returned Simulink.SimulationData.Signal object.

sigLogRef = Simulink.SimulationData.DatasetRef('out.mat','logsout');
firstSig = sigLogRef{1}
ans = 

  Simulink.SimulationData.Signal
  Package: Simulink.SimulationData

  Properties:
              Name: 'x1'
    PropagatedName: ''
         BlockPath: [1x1 Simulink.SimulationData.BlockPath]
          PortType: 'outport'
         PortIndex: 1
            Values: [1×1 matlab.io.datastore.SimulationDatastore]

Version History

Introduced in R2017a