setElement - Change Simulink.SimulationData.Dataset object element stored at
specified index - MATLAB ([original](https://in.mathworks.com/help/simulink/slref/simulink.simulationdata.dataset.setelement.html)) ([raw](?raw))
Change Simulink.SimulationData.Dataset
object element stored at specified index
Syntax
Description
[ds](#buqzxz9-1-dataset) = setElement([ds](#buqzxz9-1-dataset),[idx](#buqzxz9-1-index),[el](#buqzxz9-1-element))
replaces the element stored at the specified index ids
with the elementel
. If idx
is one greater than the number of elements in the Dataset
object ds
, the function adds the element el
to the end of the Dataset
objectds
.
ds = setElement([ds](#buqzxz9-1-dataset),[idx](#buqzxz9-1-index),[el](#buqzxz9-1-element),[name](#buqzxz9-1-name))
gives the element the name specified by name
. You can usename
to identify an element that does not have a name. If the element already has a name, the function replaces it with the name specified in thename
argument.
Examples
Use the setElement
function to:
- Change the name of a
Simulink.SimulationData.Dataset
object element. - Add a new element to a
Dataset
object. - Replace a
Dataset
object element with another element.
Create a Dataset
object.
ds = Simulink.SimulationData.Dataset;
Create four Signal
objects.
el1 = Simulink.SimulationData.Signal; el1.Name = 'A'; el2 = Simulink.SimulationData.Signal; el2.Name = 'B'; el3 = Simulink.SimulationData.Signal; el3.Name = 'C'; el4 = Simulink.SimulationData.Signal; el4.Name = 'D';
Add the Signal
objects named A
and B
to the Dataset
object.
ds = addElement(ds,el1); ds = addElement(ds,el2)
ds = Simulink.SimulationData.Dataset '' with 2 elements
Name BlockPath
____ _________
1 [1x1 Signal] A ''
2 [1x1 Signal] B ''
- Use braces { } to access, modify, or add elements using index.
You can use the setElement
function to change the name of a Dataset
object element. Change the name of the second signal from B
to Bchanged
.
ds = setElement(ds,2,el2,"Bchanged")
ds = Simulink.SimulationData.Dataset '' with 2 elements
Name BlockPath
________ _________
1 [1x1 Signal] A ''
2 [1x1 Signal] Bchanged ''
- Use braces { } to access, modify, or add elements using index.
Because the Dataset
object ds
contains two elements, you can use the setElement
function with the index 3
to add the element named C
to the Dataset
object.
ds = setElement(ds,3,el3)
ds = Simulink.SimulationData.Dataset '' with 3 elements
Name BlockPath
________ _________
1 [1x1 Signal] A ''
2 [1x1 Signal] Bchanged ''
3 [1x1 Signal] C ''
- Use braces { } to access, modify, or add elements using index.
You can also use the setElement
function to replace one element with another. Replace the element named A
with the element named D
.
ds = setElement(ds,1,el4)
ds = Simulink.SimulationData.Dataset '' with 3 elements
Name BlockPath
________ _________
1 [1x1 Signal] D ''
2 [1x1 Signal] Bchanged ''
3 [1x1 Signal] C ''
- Use braces { } to access, modify, or add elements using index.
Input Arguments
Dataset
object for which to set the element, specified as aSimulink.SimulationData.Dataset
object.
Index of element, specified as positive integer.
- To change an existing element, the index must be less than or equal to the number of elements in the
Dataset
object. - To add an element, the index must be one more than the number of elements in the
Dataset
object.
Element to replace existing element or to add to the data set, specified as aSimulink.SimulationData.Dataset
object element.
When a Dataset
object is created by logging simulation data, each element contains data for one logged signal, output, data store, or state. Each element is an object, and the type of the object depends on the data it contains.
- Signals and output — Simulink.SimulationData.Signal object
- States and final states — Simulink.SimulationData.State object
- Data stores — Simulink.SimulationData.DataStoreMemory object
When you create a Dataset
object that groups simulation input data, each element contains data for a signal, bus, or array of buses. You can add data in any format supported by the loading method you use.
Type of Input | Data Formats |
---|---|
Scalar, vector, or multidimensional signal | timeseriestimetableSimulink.SimulationData.Signalmatlab.io.datastore.SimulationDatastorematlab.io.datastore.sdidatastoreStructure with one field called signals.values that contains data for a single signal and a field calledtime that optionally includes time dataArray where the first column contains time data and subsequent columns contain data for a signal |
Bus | Structure of timeseries, timetable, or matlab.io.datastore.SimulationDatastore objects that matches the hierarchy of the busSimulink.SimulationData.Signal |
Array of buses | Array of structuresSimulink.SimulationData.Signal |
Function-call signal | _N_-by-1 vectorSimulink.SimulationData.Signal |
Element name, specified as a string or character vector.
Output Arguments
Data set in which to change an element, specified as a character vector.
Alternative
You can use curly braces to streamline indexing syntax to change an element in aDataset
object instead of using setElement
. The index must be a positive integer that is not greater than the number of elements in the variable. For example, change the name of second element of the logsout
Dataset
object.
logsout{2}.Name = 'secondSignal'
Version History
Introduced in R2011a
See Also
Objects
- Simulink.SimulationData.BlockPath | Simulink.SimulationData.Signal | Simulink.SimulationData.DataStoreMemory | Simulink.SimulationData.Dataset
Functions
- addElement | concat | find | get | getElementNames | numElements | removeElement