Simulink.SimulationData.forEachTimeseries
Call function on each timeseries
object
Description
dataResults = Simulink.SimulationData.forEachTimeseries(
runs
the specified function handle on all MATLAB® functionHandle
,inputData
)timeseries
objects
contained in inputData
.
Examples
Find Minimum for Logged Bus Signal Data
This example shows how to use the
forEachTimeseries
function to run the min
function
on each timeseries
object in the logged data for the
COUNTERBUS
signal.
Open the model and simulate it.
openExample('sldemo_mdlref_bus') sim('sldemo_mdlref_bus');
Access the signal logging data. For this model, that data is stored in the
topOut
variable.
topOut
Simulink.SimulationData.Dataset 'topOut' with 4 elements Name BlockPath ____________ ________________________________________ 1 [1x1 Signal] COUNTERBUS sldemo_mdlref_bus/Concatenate 2 [1x1 Signal] OUTERDATA sldemo_mdlref_bus/CounterA 3 [1x1 Signal] INCREMENTBUS sldemo_mdlref_bus/IncrementBusCreator 4 [1x1 Signal] INNERDATA ...erA|sldemo_mdlref_counter_bus/COUNTER - Use braces { } to access, modify, or add elements using index.
Find the values for the COUNTERBUS
element.
counterbusData = topOut{1}.Values
counterbusData = 2×1 struct array with fields: data limits
Run the min
function on the counterbus
data.
ret = Simulink.SimulationData.forEachTimeseries(@min,counterbusData)
ret = 2x1 struct array with fields: data limits
Explore the returned data.
ret(1)
ans = data: 0 limits: [1x1 struct]
ret(2).limits
ans = upper_saturation_limit: 40 lower_saturation_limit: 0
Input Arguments
functionHandle
— Function to run on MATLAB timeseries
objects
function handle
Function to run on timeseries
objects, specified
as a function handle. For information about specifying function handles,
see Pass Function to Another Function.
The function that you use with forEachTimeseries
:
Can be either a built-in function or a user-specified function
Must return a scalar
If the function that you use with forEachTimeseries
takes:
One argument, specify the function handle and the input data. For example:
ret = Simulink.SimulationData.forEachTimeseries(@min,data);
More than one argument, specify the function handle as
@(x)
and then specify the function, usingx
as the first argument. For remaining arguments, specify values. For example, this command runs theresample
function on MATLABtimeseries
objects in data, for the time vector[2.5 3]
.ret = Simulink.SimulationData.forEachTimeseries(@(x)... (resample(x,[2.5 3])),data);
inputData
— Data to run specified function on
MATLAB timeseries
object | array of timeseries
| structure with timeseries
at leaf nodes | array of structures with timeseries
at leaf
nodes
Data to run specified function on, specified as timeseries
data.
Output Arguments
dataResults
— Data resulting from running specified function
MATLAB timeseries
object | array of timeseries
| structure with timeseries
at leaf nodes | array of structures with timeseries
at leaf
nodes
Data resulting from running specified function, returned using the format and hierarchy of the input data.
Related Links
MATLAB timeseries
Function Handles
Version History
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
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)