get
Get element or collection of elements from
Simulink.SimulationData.Dataset
object
Description
returns the element in the element
= get(dataset
,index
)Simulink.SimulationData.Dataset
object
dataset
corresponding to the index. The getElement
function uses the same syntax and behavior as the get
function.
Examples
Access Data Programmatically
Access a Simulink.SimulationData.Dataset
object and its elements.
Simulate the model sldemo_clutch
, which models a rotating clutch system. Then, access the Dataset
object sldemo_clutch_output
, which contains the signal logging data. For more information about the model, see Building a Clutch Lock-Up Model.
sim("sldemo_clutch");
sldemo_clutch_output
sldemo_clutch_output = Simulink.SimulationData.Dataset 'sldemo_clutch_output' with 10 elements Name BlockPath ____________ _________________________________ 1 [1x1 Signal] Fn sldemo_clutch/Clutch Pedal 2 [1x1 Signal] Tin sldemo_clutch/Engine Torque 3 [1x1 Signal] LockedFlag sldemo_clutch/Friction Mode Logic 4 [1x1 Signal] LockupFlag sldemo_clutch/Friction Mode Logic 5 [1x1 Signal] UnlockFlag sldemo_clutch/Friction Mode Logic 6 [1x1 Signal] Tfmaxk sldemo_clutch/Friction Model 7 [1x1 Signal] Tfmaxs sldemo_clutch/Friction Model 8 [1x1 Signal] ShaftSpeed sldemo_clutch/Locked 9 [1x1 Signal] EngineSpeed sldemo_clutch/Unlocked 10 [1x1 Signal] VehicleSpeed sldemo_clutch/Unlocked - Use braces { } to access, modify, or add elements using index.
To access Dataset
object elements, you can use indexing with curly braces. For example, access the Tin
element of the signal logging Dataset
object using the index 2
.
el2 = sldemo_clutch_output{2}
el2 = Simulink.SimulationData.Signal Package: Simulink.SimulationData Properties: Name: 'Tin' PropagatedName: '' BlockPath: [1x1 Simulink.SimulationData.BlockPath] PortType: 'outport' PortIndex: 1 Values: [1x1 timeseries] Methods, Superclasses
The signal data is stored in the Values
property of the Simulink.SimulationData.Signal
object as a timeseries
object. The time values are in the Time
property of the timeseries
object. The signal values are in the Data
property.
el2.Values
timeseries Common Properties: Name: 'Tin' Time: [387x1 double] TimeInfo: tsdata.timemetadata Data: [387x1 double] DataInfo: tsdata.datametadata
Access Dataset Elements By Index
Simulate the model GetDatasetElements
, which logs data generated by three source blocks using the Dataset
format.
out = sim("GetDatasetElements");
By default, all logged data is returned in a single variable in the workspace as a Simulink.SimulationOutput
object named out
. Logged output data is grouped in Simulink.SimulationData.Dataset
object with the default name yout
. You can access the logged output data using dot notation.
out.yout
ans = Simulink.SimulationData.Dataset 'yout' with 3 elements Name BlockPath ________ _______________________ 1 [1x1 Signal] SameName GetDatasetElements/Out1 2 [1x1 Signal] SameName GetDatasetElements/Out2 3 [1x1 Signal] DifName GetDatasetElements/Out3 - Use braces { } to access, modify, or add elements using index.
Use the get
function to access the second element of the Dataset
object using the index 2
.
el = get(out.yout,2)
el = Simulink.SimulationData.Signal Package: Simulink.SimulationData Properties: Name: 'SameName' PropagatedName: '' BlockPath: [1x1 Simulink.SimulationData.BlockPath] PortType: 'inport' PortIndex: 1 Values: [1x1 timeseries] Methods, Superclasses
Access Dataset Elements By Name
The model GetDatasetElements
logs data generated by three source blocks using the Dataset
format. In the model, the signals coming from the Sine Wave block and the Constant block share the same name. The signal coming from the Pulse Generator block has a unique name.
open_system("GetDatasetElements")
Simulate the model.
out = sim("GetDatasetElements");
By default, all logged data is returned in a single variable in the workspace as a Simulink.SimulationOutput
object named out
. Access the Simulink.SimulationData.Dataset
object that contains the logged output data using dot notation.
out.yout
ans = Simulink.SimulationData.Dataset 'yout' with 3 elements Name BlockPath ________ _______________________ 1 [1x1 Signal] SameName GetDatasetElements/Out1 2 [1x1 Signal] SameName GetDatasetElements/Out2 3 [1x1 Signal] DifName GetDatasetElements/Out3 - Use braces { } to access, modify, or add elements using index.
Use the get
function to return the element with the name DifName
. Because the name DifName
is unique, the function returns a Simulink.SimulationData.Signal
object for that element.
el = get(out.yout,"DifName")
el = Simulink.SimulationData.Signal Package: Simulink.SimulationData Properties: Name: 'DifName' PropagatedName: '' BlockPath: [1x1 Simulink.SimulationData.BlockPath] PortType: 'inport' PortIndex: 1 Values: [1x1 timeseries] Methods, Superclasses
You can also use the get
function when an element is not unique. Because the name SameName
is not unique, the function returns a Simulink.SimulationData.Dataset
object containing the elements with the name SameName
.
ds = get(out.yout,"SameName")
ds = Simulink.SimulationData.Dataset '' with 2 elements Name BlockPath ________ _______________________ 1 [1x1 Signal] SameName GetDatasetElements/Out1 2 [1x1 Signal] SameName GetDatasetElements/Out2 - Use braces { } to access, modify, or add elements using index.
Access Dataset Elements With Cell Array
The model GetDatasetElements
logs data generated by three source blocks using the Dataset
format. In the model, the signals coming from the Sine Wave block and the Constant block share the same name. The signal coming from the Pulse Generator block has a unique name.
open_system("GetDatasetElements")
Simulate the model.
out = sim("GetDatasetElements");
By default, all logged data is returned in a single variable in the workspace as a Simulink.SimulationOutput
object named out
. Access the Simulink.SimulationData.Dataset
object that contains the logged output data using dot notation.
out.yout
ans = Simulink.SimulationData.Dataset 'yout' with 3 elements Name BlockPath ________ _______________________ 1 [1x1 Signal] SameName GetDatasetElements/Out1 2 [1x1 Signal] SameName GetDatasetElements/Out2 3 [1x1 Signal] DifName GetDatasetElements/Out3 - Use braces { } to access, modify, or add elements using index.
Use the get
function with a cell array containing a character vector to return a Dataset
object. If the element name is unique, the get
function returns a Dataset
object containing one element. If the element name is not unique, the get
function returns a Dataset
object containing all elements with that name. For example, create a Dataset
object containing the element named DifName
.
ds = get(out.yout,{'DifName'})
ds = Simulink.SimulationData.Dataset '' with 1 element Name BlockPath _______ _______________________ 1 [1x1 Signal] DifName GetDatasetElements/Out3 - Use braces { } to access, modify, or add elements using index.
Access Bus Data Logged Using Dataset
Format
The model AccessDatasetNestedBus
contains nested arrays of buses. Two arrays of buses, Bus2
and Bus3
, are marked for logging. topBus
is logged using an Outport block. This example shows how to access Dataset
elements within the bus hierarchy.
Open and simulate the model.
mdl = "AccessDatasetNestedBus";
open_system(mdl)
out = sim(mdl);
All logged data is returned in a single variable, out
, as a Simulink.SimulationOutput
object. Access the Dataset
object that contains signal logging data, logsout
, using dot notation.
ds = out.logsout
ds = Simulink.SimulationData.Dataset 'logsout' with 2 elements Name BlockPath ____ ________________________________________ 1 [1x1 Signal] Bus3 ...ssDatasetNestedBus/Matrix Concatenate 2 [1x1 Signal] Bus2 ...sDatasetNestedBus/Vector Concatenate1 - Use braces { } to access, modify, or add elements using index.
Data for topBus
is logged to the Dataset
object yout
.
ds2 = out.yout
ds2 = Simulink.SimulationData.Dataset 'yout' with 1 element Name BlockPath ______ ___________________________ 1 [1x1 Signal] topBus AccessDatasetNestedBus/Out1 - Use braces { } to access, modify, or add elements using index.
You can use the get
function to access signal logging information for each element in the Dataset
object. For example, use the get
function to return the Simulink.SimulationData.Signal
object for the array of buses named Bus2
.
get(ds,"Bus2")
ans = Simulink.SimulationData.Signal Package: Simulink.SimulationData Properties: Name: 'Bus2' PropagatedName: '' BlockPath: [1x1 Simulink.SimulationData.BlockPath] PortType: 'outport' PortIndex: 1 Values: [2x1 struct] Methods, Superclasses
The logged data values are stored in the Values
property of the Signal
object. For an array of buses, the data is logged as an array of MATLAB® structures.
get(ds,"Bus2").Values
ans=2×1 struct array with fields:
a
b
You can access a specific structure using the index of the structure within the array. For example, to access the structure that contains timeseries
objects for the signals coming from the Constant blocks Constant6
and Constant7
, use the index 2
.
get(ds,"Bus2").Values(2)
ans = struct with fields:
a: [1x1 timeseries]
b: [1x1 timeseries]
Access a timeseries
object within the structure using dot notation. For example, access the timeseries
object for the signal coming from the Constant6
block.
get(ds,"Bus2").Values(2).a
timeseries Common Properties: Name: 'a' Time: [51x1 double] TimeInfo: tsdata.timemetadata Data: [51x1 double] DataInfo: tsdata.datametadata
Signal values are stored in the Data
property.
get(ds,"Bus2").Values(2).a.Data
ans = 51×1
6
6
6
6
6
6
6
6
6
6
⋮
Suppose that you did not want to mark Bus2
for logging. You can also get signal values for the signal coming from the Constant6
block using the Dataset
object element Bus3
.
get(ds,"Bus3").Values(2,2).a.Data
ans = 51×1
6
6
6
6
6
6
6
6
6
6
⋮
Similarly, you can also access signal values for the signal coming from the Constant6
block using the Dataset
object element topBus
.
get(ds2,"topBus").Values.Bus3(2,2).a.Data
ans = 51×1
6
6
6
6
6
6
6
6
6
6
⋮
Input Arguments
dataset
— Dataset
object
Simulink.SimulationData.Dataset
object
Dataset
object from which to get the element, specified as a
Simulink.SimulationData.Dataset
object.
index
— Index of element to get
positive integer
Index of element to get, specified as a positive integer.
elName
— Name of Dataset
object element to get
string | character array | cell array containing one character vector
Name of Dataset
object element to get, specified as:
A string reflecting the name of the
Dataset
object element.A character array reflecting the name of the
Dataset
object element.A cell array containing one character vector reflecting the name of the
Dataset
object element. To return aDataset
object that can contain one element, use this format. Consider this form when writing scripts.
Alternatives
Instead of using get
or getElement
, you can use
curly braces to streamline the indexing syntax to access an element in a
Dataset
object. The index must be a positive integer that is not greater
than the number of elements in the variable. For example, get the second element of the
logsout
dataset.
logsout{2}
You can also use the find
function to get an element or collection of
elements from a dataset.
Version History
Introduced in R2011a
See Also
Objects
Simulink.SimulationData.BlockPath
|Simulink.SimulationData.Signal
|Simulink.SimulationData.DataStoreMemory
|Simulink.SimulationData.Dataset
Functions
addElement
|concat
|find
|getElementNames
|numElements
|removeElement
|setElement
Ouvrir l'exemple
Vous possédez une version modifiée de cet exemple. Souhaitez-vous ouvrir cet exemple avec vos modifications ?
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)