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

10 次查看(过去 30 天)
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

采纳的回答

Siegmund Nuyts
Siegmund Nuyts 2022-10-13
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by