Main Content

Simulink.sdi.DatasetRef

Access data in Simulation Data Inspector repository

Description

A Simulink.sdi.DatasetRef object references data for a run in the Simulation Data Inspector allowing you to work with signal data in the run while controlling when and how the signal data is loaded into memory. The Simulink.sdi.DatasetRef object references data from a Simulation Data Inspector run similarly to how a Simulink.SimulationData.DatasetRef object references a data in a MAT file. To access signal data in the repository without loading the signal data into memory, use the getSignal function. To work with Run elements outside the Simulation Data Inspector, use the getElement function to copy signal data from the repository to the workspace.

Creation

Description

example

dsr_array = Simulink.sdi.DatasetRef creates an array that contains a Simulink.sdi.DatasetRef object corresponding to each run in the Simulation Data Inspector.

dsr_array = Simulink.sdi.DatasetRef(domain) creates an array of DatasetRef objects with the contents of each run limited to the specified domain.

example

dsr = Simulink.sdi.DatasetRef(runID) creates a Simulink.sdi.DatasetRef object that references the run specified by the run identifier runID.

dsr = Simulink.sdi.DatasetRef(runID, domain) creates a Simulink.sdi.DatasetRef object that references the run specified by runID with contents specified by domain.

dsr = Simulink.sdi.DatasetRef(runID, domain, repositoryPath) creates a Simulink.sdi.DatsetRef object that references the run specified by the run identifier, runID. The DatasetRef object contains the contents specified by domain from the repository specified by repositoryPath.

Input Arguments

expand all

Data to reference in DatasetRef object, specified as one of these options:

  • "signals" — Signals produced by signal logging

  • "outports" — Model output signals, represented by top-level Outport blocks

  • "dsm"Data Store Memory blocks

  • "state" — Simulink® states

  • "param" — Parameter data for block parameters and variables tuned using dashboard blocks

  • "sf_data" — Stateflow® local data

  • "sf_state" — Stateflow states

  • "sf_state_child" — Stateflow child activity

  • "sf_state_leaf" — Stateflow leaf activity

  • "slt_verify"Assertion blocks and verify assessments in Simulink Test™

Run identifier of the run containing the data for the Simulink.sdi.DatasetRef object, specified as a positive integer.

Path containing the run with the data for the Simulink.sdi.DatasetRef object, specified as a string or character vector.

Properties

expand all

This property is read-only.

Run name that corresponds with the Simulink.sdi.DatasetRef object, specified as a character vector.

This property is read-only.

Run object associated with the Simulink.sdi.DatasetRef object, specified as a Simulink.sdi.Run object.

This property is read-only.

Number of top-level elements in the Simulink.sdi.Run object associated with the Simulink.sdi.DatasetRef object, specified as a positive integer.

Object Functions

compare Compare runs referenced by Simulink.sdi.DatasetRef objects
getAsDatastoreGet matlab.io.datastore.sdidatastore representation of signal in referenced Simulation Data Inspector run
getElementCopy signal data from Simulation Data Inspector run to workspace
getElementNamesGet names of all elements in referenced Simulation Data Inspector run
getSignalGet signal data from Simulation Data Inspector run
plot Open Simulation Data Inspector to view and compare data

Examples

collapse all

The model ex_sldemo_absbrake uses a Constant block to specify a slip setpoint for an anti-lock braking system. Simulate the model with two different slip setpoint values, 0.24 and 0.25, and compare the output wheel speed of each simulation run using Simulink.sdi.DatasetRef objects.

Set the value of the Desired relative slip block to 0.25. Then, simulate the model.

load_system("ex_sldemo_absbrake")
set_param("ex_sldemo_absbrake/Desired relative slip", "Value", "0.25")
sim("ex_sldemo_absbrake");

To create another run, change the value of the Desired relative slip block to 0.24 and simulate the model again.

set_param("ex_sldemo_absbrake/Desired relative slip", "Value", "0.24")
sim("ex_sldemo_absbrake");

Create an array of Simulink.sdi.DatasetRef objects corresponding to each run in the Simulation Data Inspector.

DSR_Runs = Simulink.sdi.DatasetRef;

Compare the results from the two runs.

[matches, mismatches, diffResult] = compare(DSR_Runs(1),DSR_Runs(2))
matches = 0
mismatches = 4
diffResult = 
  DiffRunResult with properties:

       MatlabVersion: '24.1.0.2508561 (R2024a)'
              RunID1: 11469
              RunID2: 11509
     BaselineRunName: 'Run 1: ex_sldemo_absbrake'
    CompareToRunName: 'Run 2: ex_sldemo_absbrake'
               Count: 4
         DateCreated: 13-Feb-2024 01:28:51
     GlobalTolerance: [1x1 struct]
             Summary: [1x1 struct]
             Options: {'Units'  'MustMatch'}
              Status: Completed
          StopReason: []

You can plot data from a Simulation Data Inspector run referenced by a Simulink.sdi.DatasetRef object in the Simulation Data Inspector programmatically.

Simulate the model ex_sldemo_absbrake to create a run of logged signals.

mdl = "ex_sldemo_absbrake";
sim(mdl)

Use the Simulink.sdi.Run.getLatest function to get the latest run.

brakeRun = Simulink.sdi.Run.getLatest;

Create a Simulink.sdi.DatasetRef object that references the run.

runID = brakeRun.ID;
DSRef = Simulink.sdi.DatasetRef(runID);

Get the names of the elements in the referenced run.

names = getElementNames(DSRef)
names = 2x1 cell
    {'yout'}
    {'slp' }

Use the getSignal function to get the yout bus. You can access the elements of the bus using the Values parameter.

yout = getSignal(DSRef,1);
outputs = yout.Values
outputs = struct with fields:
    Ww: [1x1 timeseries]
    Vs: [1x1 timeseries]
    Sd: [1x1 timeseries]

Use the getSignal function to get the slp signal. Set the Checked property to true to select the signal for plotting in the Simulation Data Inspector.

slp = getSignal(DSRef,"slp");
slp.Checked = 'true';

Open the Simulation Data Inspector to view signals.

plot(DSRef)

Version History

Introduced in R2017b