Documentation

Simulink.SimulationData.Dataset class

Package: Simulink.SimulationData
Superclasses:

Create Simulink.SimulationData.Dataset object

Description

Simulink® creates Simulink.SimulationData.Dataset objects to store data elements when:

  • Performing signal logging, which use the Dataset format

  • Logging states or outputs, if you use the default format of Dataset.

  • Logging a data store

Using the Dataset format for state and output logging offers several advantages compared to Array, Structure, or Structure with time. For details, see Format for State Information Saved Without SimState.

To generate a Simulink.SimulationData.Dataset object from the root-level Inport blocks in a model, you can use the createInputDataset function. Signals in the generated dataset have the properties of the Inport blocks and the corresponding ground values at model start and stop times. You can create timeseries and timetable objects for the time and values for signals for which you want to load data for simulation. The other signals use ground values.

You can use curly braces ({}) to streamline indexing syntax to access, set, and add elements in a dataset, instead of using get, getElement, setElement, or addElement methods. To get or set an element using curly braces, the index must be a scalar that is not greater than the number of elements in the dataset variable. To add an element, the index must be a scalar that is greater than the total number of elements in the dataset by one. The get, getElement, setElement, or addElement methods support specifying an element by name or block path, as well as by index.

For individual non-bus signal data, you can specify these types of data for Dataset elements:

  • timeseries

  • timetable

  • matlab.io.datastore.SimulationDatastore

  • double vectors or structure of double data

  • timeseries

  • a Simulink.SimulationData.Signal, Simulink.SimulationData.State, or Simulink.SimulationData.DataStoreMemory object

For bus signals, use a structure with a data element for each leaf signal, using one of these formats:

  • A MATLAB® timeseries object

  • A MATLAB timetable object

  • A matlab.io.datastore.SimulationDatastore object

  • An empty matrix

  • An array that meets one of these requirements:

    • An array with time in the first column and the remaining columns each corresponding to an input port. See Create Data Arrays for Root-Level Inputs.

    • An nx1 array for a root inport that drives a function-call subsystem.

  • Another structure, with data elements for each signal that are consistent with these requirements for a structure for bus data

Variable-size signals are not supported for Dataset data values.

Construction

convertedDataset = Simulink.SimulationData.Dataset(loggedDataToConvert) converts the loggedDataToConvert to a Simulink.SimulationData.Dataset object. You can then use the Simulink.SimulationData.Dataset.concat method to combine elements of two Dataset objects.

constructedDataset = Simulink.SimulationData.Dataset(variableName,'DatasetName','dsname') constructs a Simulink.SimulationData.Dataset object, adds variable variableName, and names the data set dsname.

Input Arguments

expand all

Data element to convert to a data set, specified as a character vector. You can convert elements such as:

  • Array

  • Structure

    Note

    Structure inputs cannot be arrays or matrices.

  • Structure with time

  • MATLAB time series

  • Structure of MATLAB time-series elements

  • ModelDataLogs

Variable to add to data set, specified as a character vector.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'DatasetName','dsname'

expand all

Data set name, specified as a character vector.

Output Arguments

expand all

Converted data set, returned as a Simulink.SimulationData.Dataset object.

Constructed data set, returned as a Simulink.SimulationData.Dataset object.

Properties

expand all

Name of the data set, specified as a character vector or logging variable (for example, logsout for signal logging). Specify a name when you want to distinguish easily one data set from another. For example, you could reset the name when comparing multiple simulations. This property is read/write.

ds = Simulink.SimulationData.Dataset
ds.Name = 'Dataset1'

Total number of elements in data set, specified as a double. This property is read only. To get this value, use the Simulink.SimulationData.Dataset.numElements method.

Methods

addElementAdd element to end of data set
concatConcatenate dataset to another dataset
findGet element or collection of elements from dataset
getGet element or collection of elements from dataset
getElementNamesReturn names of all elements in dataset
numElementsGet number of elements in data set
plotPlot dataset elements in Signal Preview window or Simulation Data Inspector
setElementChange element stored at specified index

Tip

To get the names of Dataset variables in the MAT-file, using the Simulink.SimulationData.DatasetRef.getDatasetVariableNames function processes faster than using the who or whos functions.

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects (MATLAB).

Examples

expand all

Convert data from two To Workspace blocks, convert to Dataset format, and concatenate them. myvdp is the vdp model with two To Workspace blocks with variables named simout and simout1. These blocks log data in time-series format.

mdl = 'myvdp';
open_system(mdl);
sim(mdl)
ds = Simulink.SimulationData.Dataset(simout);
ds1 = Simulink.SimulationData.Dataset(simout1);
dsfinal = concat(ds,ds1)

Use curly brace indexing syntax to work with a logsout signal logging dataset that has three elements.

Get the second element of the logsout dataset.

logsout{2}

Change the name of the third element.

logsout{3}.Name = 'thirdSignal'

Add a fourth element.

time = 0.1*(0:100)';
element4 = Simulink.SimulationData.Signal;
element4.Name = 'C';
element4.Values = timeseries(3*sin(time),time);
logsout{4} = element4

Introduced in R2011a

Was this topic helpful?