Simulink.SimulationData.forEachTimeseries
Apply function to data contained in set of timeseries
objects
Description
applies the function res
= Simulink.SimulationData.forEachTimeseries(func
,tsData
)func
to each timeseries
object in tsData
. You can use this function to
postprocess data logged from a bus or array of buses.
Examples
Find Minimum Values for Signals in Bus
Open the model named BusHierarchy
. The model groups the output signals from a Chirp block and a Sine block into a bus that is nested in another bus. The top-level bus also contains the output signal from a Step block. To update the bus line styles, on the Modeling tab of the Simulink Toolstrip, click Update Model or Run.
Mark the bus named TopBus
for logging.
Simulink.sdi.markSignalForStreaming("BusHierarchy/Bus Creator1",1,true);
Simulate the model.
out = sim("BusHierarchy");
The Simulink.SimulationOutput
object contains simulation metadata and all simulation data logged to the workspace.
out
out = Simulink.SimulationOutput: logsout: [1x1 Simulink.SimulationData.Dataset] tout: [53x1 double] SimulationMetadata: [1x1 Simulink.SimulationMetadata] ErrorMessage: [0x0 char]
The variable named logsout
contains the data logged for the bus.
logsout = out.logsout
logsout = Simulink.SimulationData.Dataset 'logsout' with 1 element Name BlockPath ______ _________________________ 1 [1x1 Signal] TopBus BusHierarchy/Bus Creator1 - Use braces { } to access, modify, or add elements using index.
Access the signal that contains the data logged for the bus named TopBus
. The signal values are stored in the Values
property for the Simulink.SimulationData.Signal
object.
topBusSig = getElement(logsout,1)
topBusSig = Simulink.SimulationData.Signal Package: Simulink.SimulationData Properties: Name: 'TopBus' PropagatedName: '' BlockPath: [1x1 Simulink.SimulationData.BlockPath] PortType: 'outport' PortIndex: 1 Values: [1x1 struct]
Access the structure that contains the values for the signals in the bus. The structure hierarchy and field names match the hierarchy and signal names for the bus. The data for each signal in the bus is stored as a timeseries
object.
topBusData = topBusSig.Values
topBusData = struct with fields:
NestedBus: [1x1 struct]
Step: [1x1 timeseries]
Use the Simulink.SimulationData.forEachTimeseries
function to find the minimum value for each signal in the bus. The minimum values are returned as a structure with the same fields and hierarchy as the input data.
topBusSigMins = Simulink.SimulationData.forEachTimeseries(@min,topBusData)
topBusSigMins = struct with fields:
NestedBus: [1x1 struct]
Step: 0
Check the minimum value for the output signal from the Chirp block.
chirpMin = topBusSigMins.NestedBus.Chirp
chirpMin = -0.9972
Input Arguments
func
— Function to apply to data
function handle
Function to apply to data, specified as a function handle. For more information, see Create Function Handle.
The function that you specify must take at least one input argument and return a scalar. You can specify a handle for a built-in function, a function you create, or an anonymous function.
For example, you can use the built-in min
function to compute
the minimum value in each timeseries
object.
res = Simulink.SimulationData.forEachTimeseries(@min,tsData);
When the function takes more than one input argument, only the argument for the
timeseries
object can change for each computation. The rest of the
arguments must use the same values for each timeseries
object.
For example, to apply the resample
function to each
timeseries
object, specify the function as an anonymous function.
Here, the variable tsData represents the timeseries
objects. The other arguments for the resample
function are passed
as parameter values. The Simulink.SimulationData.forEachTimeseries
function passes the timeseres
data you specify in the second input
argument to the anonymous function as the value for
tsData.
res = Simulink.SimulationData.forEachTimeseries(...
@(tsData) resample(tsData,[2.5 3]),tsData);
Data Types: function_handle
tsData
— Data to process
scalar timeseries
object | array of timeseries
| structure of timeseries
objects | array of structures of timeseries
objects
Data to process, specified as one of these values:
Scalar
timeseries
objectArray of
timeseries
objectsStructure of
timeseries
objectsArray of structures of
timeseries
objects
Output Arguments
res
— Results of processing data
scalar timeseries
object | array of timeseries
| structure of timeseries
objects | array of structures of timeseries
objects
Results of processing data, returned as one of these values:
Scalar
timeseries
objectArray of
timeseries
objectsStructure of
timeseries
objectsArray of structures of
timeseries
objects
Results are returned in the same form as the input data.
Version History
Introduced in R2016b
See Also
Objects
timeseries
|Simulink.SimulationOutput
|Simulink.SimulationData.Dataset
|Simulink.SimulationData.Signal
Topics
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi 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)