convert hourly data to daily sum

10 vues (au cours des 30 derniers jours)
BC15
BC15 le 10 Nov 2020
I have a mat file. Date and time (hour) in first column and melt in second column and I want to sum the hourly data into a daily value.

Réponses (2)

David Hill
David Hill le 10 Nov 2020
load('hourmelt.mat');
a=[month(hourmelt.DateandTime),day(hourmelt.DateandTime),year(hourmelt.DateandTime)];
b=unique(a,'rows','stable');
c=arrayfun(@(x)sum(hourmelt.HourlyValue(ismember(a,b(x,:),'rows'))),1:length(b))';
newMatrix=[b,c];

Peter Perkins
Peter Perkins le 20 Nov 2020
Turn your table into a timetable, and use retime:
>> hourmelt = table2timetable(hourmelt);
>> head(hourmelt)
ans =
8×1 timetable
DateandTime HourlyValue
___________________ ___________
01/01/2015 00:00:00 0
01/01/2015 01:00:00 0
01/01/2015 02:00:00 0
01/01/2015 03:00:00 0
01/01/2015 04:00:00 0
01/01/2015 05:00:00 0
01/01/2015 06:00:00 0
01/01/2015 07:00:00 0
>> head(dailymelt)
ans =
8×1 timetable
DateandTime HourlyValue
___________________ ___________
01/01/2015 00:00:00 0
02/01/2015 00:00:00 0
03/01/2015 00:00:00 0
04/01/2015 00:00:00 0
05/01/2015 00:00:00 0
06/01/2015 00:00:00 0
07/01/2015 00:00:00 0
08/01/2015 00:00:00 0
>> head(dailymelt(dailymelt.HourlyValue > 0,:))
ans =
8×1 timetable
DateandTime HourlyValue
___________________ ___________
07/06/2015 00:00:00 0.03
08/06/2015 00:00:00 0.23
09/06/2015 00:00:00 0.32
10/06/2015 00:00:00 0.43
11/06/2015 00:00:00 0.47
12/06/2015 00:00:00 0.62
13/06/2015 00:00:00 0.6
14/06/2015 00:00:00 0.83

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by