Average timestamp 20 seconds interval data into hourly
1 次查看(过去 30 天)
显示 更早的评论
Hi I have a excel file having 2 columns of data i.e. timestamp and vlaues. The timestamp is at interval of 20 seconds. I want this to be averaged on hourly basis . Also data corresponding to timestamp column be averaged.
Also when these 2 columns are averaged. It should update excel file or write it to a new file.
Timestamp data 01.01.2015 00:00:00 10 01.01.2015 00:00:20 12 01.01.2015 00:00:40 14 01.01.2015 00:01:00 8
0 个评论
回答(2 个)
Andrei Bobrov
2017-8-21
for older version MATLAB:
T = readtable('data.xls');
[Y M D H] = datevec(T{:,1});
[~,~,T.groups] = unique([Y M D H],'rows');
T_temp = varfun(@mean,T,'G','groups');
T_out = T_temp(:,3:4);
T_out.Properties.VariableNames = T.Properties.VariableNames(1:2);
writetable(T_out,'data2.xlsx')
11 个评论
Andrei Bobrov
2017-9-4
T = readtable('B.xls');
T.Timestamp = datetime(T{:,1},'I','dd.MM.uuuu HH:mm:ss');
[Y,M,D,H] = datevec(T.Timestamp);
[a,~,c] = unique([Y,M,D,H],'rows');
T_out = table(datetime([a,zeros(size(a,1),2)],'F','uuuu-MM-dd HH:mm'),accumarray(c,T.data,[],@mean),'v',{'Timestamp','data'});
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!