Main Content

setElement

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

Change element stored at specified index

Syntax

dataset = setElement(dataset,index,... element)
dataset = setElement(index,element, name)

Description

dataset = setElement(dataset,index,... element) changes the element stored at the specified index, for an existing index. If index is one greater than the number of elements in the data set, the function adds the element at the end of the data set.

dataset = setElement(index,element, name) changes the element stored at the specified index and gives it the name that you specify. You can use name to identify an element that does not have a name. If the signal already has a name, the element instead uses the name you specify by using the name argument.

Input Arguments

expand all

The data set for which to set the element.

Index for the added element, specified as a scalar numeric value. The value must be between 1 and the number of elements plus 1.

Element to replace existing element or to add to the data set, specified as a Simulink.SimulationData.Signal object or Simulink.SimulationData.DataStoreMemory object.

Element name, returned as a character vector.

Output Arguments

expand all

Data set in which you change or add an element, specified as a character vector.

Examples

expand all

Set element name.

ds = Simulink.SimulationData.Dataset
element1 = Simulink.SimulationData.Signal
element1.Name = 'A'
ds = ds.addElement(element1)
element2 = Simulink.SimulationData.Signal
element2.Name = 'B'
elementNew = Simulink.SimulationData.Signal
ds = ds.setElement(2,elementNew,'B1')
ds
ds = 

  Simulink.SimulationData.Dataset
  Package: Simulink.SimulationData

  Characteristics:
              Name: 'topOut'
    Total Elements: 2

  Elements:
    1: 'A'
    2: 'B1'
    
  Use getElement to access elements by index, name or 
  block path.

  Methods, Superclasses

Alternative

You can use curly braces to streamline indexing syntax to change an element in a dataset, instead of using setElement. The index must be a scalar that is not greater than the number of elements in the variable. For example, change the name of second element of the logsout dataset.

logsout{2}.Name = 'secondSignal'
Introduced in R2011a