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

14 ビュー (過去 30 日間)
Siegmund Nuyts
Siegmund Nuyts 2022 年 10 月 7 日
回答済み: Siegmund Nuyts 2022 年 10 月 13 日
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 Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by