addElement

Class: Simulink.SimulationData.Dataset
Package: Simulink.SimulationData

Add element to end of data set

Syntax

dataset = addElement(dataset,element)
dataset = addElement(dataset,element,name)

Description

dataset = addElement(dataset,element) adds an element to the Simulink.SimulationData.Dataset dataset.

dataset = addElement(dataset,element,name) adds an element to the Simulink.SimulationData.Dataset data set and gives the element the name that you specify with the name argument. If the object already has a name, the element instead uses the name you specify by using the name argument.

Input Arguments

expand all

The data set to which to add the element.

Element to add to the data set, specified as a Simulink.SimulationData.Signal, Simulink.SimulationData.DataStoreMemory, or matlab.io.datastore.SimulationDatastore object.

Name for element, specified as a character vector.

Output Arguments

expand all

The data set to which you add the element, returned as a character vector. The new element is added to the end of the data set.

Examples

expand all

Create a data set and add three elements to it.

time = 0.1*(0:100)';
ds = Simulink.SimulationData.Dataset;
element1 = Simulink.SimulationData.Signal;
element1.Name = 'A';
element1.Values = timeseries(sin(time),time);
ds = addElement(ds,element1);
element2 = Simulink.SimulationData.Signal;
element2.Name = 'B';
element2.Values = timeseries(2*sin(time),time);
ds = addElement(ds,element2);
element3 = Simulink.SimulationData.Signal;
element3.Name = 'C';
element3.Values = timeseries(3*sin(time),time);
ds = addElement(ds,element3);
ds
ds = 

Simulink.SimulationData.Dataset '' with 3 elements

                         Name  BlockPath 
                         ____  _________ 
    1  [1x1 Signal]      A     ''       
    2  [1x1 Signal]      B     ''       
    3  [1x1 Signal]      C     ''       

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

Alternative

To streamline indexing syntax, you can use curly braces ({}) to add an element to a dataset, instead of using addElement. For the index, use a scalar that is greater than the number of elements by one. The new element becomes the last element of the dataset.

time = 0.1*(0:100)';
ds = Simulink.SimulationData.Dataset;
element1 = Simulink.SimulationData.Signal;
element1.Name = 'A';
element1.Values = timeseries(sin(time),time);
ds{1} = element1;
element2 = Simulink.SimulationData.Signal;
element2.Name = 'B';
element2.Values = timeseries(2*sin(time),time);
ds{2} = element2;
element3 = Simulink.SimulationData.Signal;
element3.Name = 'C';
element3.Values = timeseries(3*sin(time),time);
ds{3} = element3;

Introduced in R2011a