getAsDatastore

Class: Simulink.SimulationData.DatasetRef
Package: Simulink.SimulationData

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

Syntax

element = Simulink.SimulationData.DatasetRef.getAsDatastore(datasetref_elements)

Description

element = Simulink.SimulationData.DatasetRef.getAsDatastore(datasetref_elements) returns a matlab.io.datastore.SimulationDatastore representation of an element or collection of elements from the referenced dataset, based on index, name, or block path of the element.

You can represent a Dataset element as a matlab.io.datastore.SimulationDatastore object if the element was placed into the MAT-file using either of these approaches:

  • Log Dataset format data to persistent storage (MAT-file).

  • Place the element into a Simulink.SimulationData.Dataset object and saved the Dataset object to a v7.3 MAT-file.

The SimulationDatastore representation for a Dataset element creates a SimulationDatastore object for the Values field of that element. The SimulationDatastore representation supports streaming of the data for the Values property of the element into other simulations or into MATLAB®.

Note

You cannot use create a SimulationDatastore for Dataset elements that contain these types of data:

  • Array

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.

Input Arguments

expand all

Element of a referenced dataset in a MAT-file, specified as an index, name (as a character vector), or block path (as a character vector.

Output Arguments

expand all

Element accessed using SimulationDatastore object, returned as either a matlab.io.datastore.SimulationDatastore object or a Simulink.Signal, Simulink.State, or similar object, whose Values data uses a matlab.io.datastore.SimulationDatastore object.

Examples

expand all

Log signal data to persistent storage (select the Log Dataset data to file configuration parameter) and simulate a model.

Create a DatasetRef for the signal logging Dataset data (logsout) in the out.mat MAT-file.

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

  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]

Load the data into another model. This approach streams the values of the signal x1 for another simulation.

ds = Simulink.SimulationData.Dataset;
ds{1} = sigLogRef{1};
sim('other_model','ExternalInput','ds');

Alternative

To streamline the use of indexing, you can use curly braces ({}) syntax to obtain a SimulationDatastore object for DatasetRef object signal values. The requirements and results are the same as using getAsDatastore. For example, if you log signal data to persistent storage (select the Log Dataset data to file configuration parameter) and simulate a model.

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]
Introduced in R2017a