# Loop through a timeseries and calculate values over a 20min interval

9 Ansichten (letzte 30 Tage)
Siegmund Nuyts am 7 Okt. 2022
Beantwortet: Siegmund Nuyts am 13 Okt. 2022
I have a timeseries with data every second for a few months and a function.
I'd like to use a subset of the timeseries as input in a function (every 20min - 1200 timesteps).
So [1:1200 1201:2400 2401:3600 ...] as input d.
How can I loop through the timeseries and get the value every 20min in an array [Time Pressure] and show the resulting value with a timstamp of 20min?
My initial idea was to use a for loop:
Times = datetime(nt, 'convertFrom', 'posixtime', 'Format', 'yyyy-MM-dd HH:mm:ss');
T = timetable(Times, pressure);
d = T.pressure;
dt = 1 %timestep (1 second)
meth = 1
for i = 1:1200:length(d) %1200 timestepds = 20 min
[X] = myfunction(d, dt, meth)
end
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Siegmund Nuyts am 13 Okt. 2022
I found a solution using a different approach:
Times = datetime(nt, 'convertFrom', 'posixtime', 'Format', 'yyyy-MM-dd HH:mm:ss');
T = timetable(Times, pressure);
dt = 1 %timestep (1 second)
meth = 1
interval = 1200;
timespan = length(T.pressure)-interval;
for jj = 1:interval:timespan
d = T.pressure(jj+(0:interval-1));
s = T.Times(jj);
[X] = myfunction(d, dt, meth)
XT = [XT; X]
Time = [Time; s]
end
TT = timetable(Time, XT);
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

R2020b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by