how to change data from 10 minutes to hour?

조회 수: 4 (최근 30일)
Jan Risn
Jan Risn 2019년 5월 8일
댓글: Jan Risn 2019년 7월 8일
I have data
x =
01/02/2015 02:20 4
02/02/2015 2:30 2
01/02/2015 02:50 0
01/02/2015 08:50 8
01/02/2015 03:00 7
01/02/2015 03:10 9
02/02/2015 3:30 4
02/02/2015 3:40 6
02/02/2015 03:50 8
...
the first step I want to normalize starts from the initial hour (2:00)
and generate data per 10 minutes with empty data filled with Nan
the second step I want to change it to average data per hour ... so that i get hourly data on each date ...
I have tried many times but this doesn't work ..
I thank all those who gave advice and were kind enough to help me.
  댓글 수: 2
Jan Risn
Jan Risn 2019년 5월 8일
01/02/2015 02:20 4
02/02/2015 2:30 2
01/02/2015 02:50 0
01/02/2015 08:50 8
01/02/2015 03:00 7
01/02/2015 03:10 9
02/02/2015 3:30 4
02/02/2015 3:40 6
02/02/2015 03:50 8
KSSV
KSSV 2019년 5월 8일
Read about interp1.

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 5월 8일
편집: Andrei Bobrov 2019년 5월 8일
In R2016b:
T = readtable('data.txt','ReadVariableNames',false,'Format','%q %q %f');
TT = sortrows(timetable(T.Var3,'RowTimes',...
datetime(strcat(T.Var1,'_',T.Var2),'I','dd/MM/uuuu_HH:mm')));
dt = dateshift(TT.Time(1),'start','hour'):...
minutes(10):dateshift(TT.Time(end),'end','hour');
TT1 = retime(TT,dt);% data per 10 minutes
TT2 = retime(TT,'hourly','mean');% average data per hour
  댓글 수: 1
Jan Risn
Jan Risn 2019년 7월 8일
thank you for the advice given. but I use matlab 2014a so there is no retime function.
can you help me improve the program script that I have created. I feel difficulties with the accumulation function.
times = record;
dn = datenum(times);
min_time = min(dn);
min_time_dv = datevec(min_time);
min_time_dv(5) = floor(min_time_dv(5) / 10) * 10;
first_slot_dn = datenum(min_time_dv);
max_time = max(dn);
max_time_dv = datevec(max_time);
max_time_dv(5) = floor(max_time_dv(5) / 10) * 10;
last_slot_dn = datenum(max_time_dv);
ten_mins_as_days = 1 / (24 * 60/10);
%%%%% get time per 10 minutes
slot_dns = first_slot_dn : ten_mins_as_days : last_slot_dn;
slot_ds = datestr(slot_dns);
times_minutes = [cellstr(slot_ds(1:end,:))];
slot_ds = datestr(slot_dns);
[~, slot_idx] = histc(dn, slot_dns);
%%% mean RR
mean_RR = accumarray(slot_idx, RR(:), [length(slot_dns)-1,1], @mean, nan);
output = [cellstr(slot_ds(1:end-1,:)), num2cell(mean_RR)];
and display results :
Error using accumarray
First input SUBS and third input SZ must satisfy ALL(MAX(SUBS)<=SZ).
the data I want per 10 minutes and generate data per 10 minutes with empty data filled with Nan
can you fix my akumarray program? I don't understand using this function. I thank you for giving advice and good enough to help me.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by