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

3 Ansichten (letzte 30 Tage)
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:
nt = ncread('pressure.nc', 'datetime');
Times = datetime(nt, 'convertFrom', 'posixtime', 'Format', 'yyyy-MM-dd HH:mm:ss');
pressure = ncread('pressure.nc', 'pressure');
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

Akzeptierte Antwort

Siegmund Nuyts
Siegmund Nuyts am 13 Okt. 2022
I found a solution using a different approach:
nt = ncread('pressure.nc', 'datetime');
Times = datetime(nt, 'convertFrom', 'posixtime', 'Format', 'yyyy-MM-dd HH:mm:ss');
pressure = ncread('pressure.nc', 'pressure');
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);

Weitere Antworten (0)

Kategorien

Mehr zu Time Series finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by