convert hourly data to daily data

Hi, I have a hourly time series and I want to convert them to daily data so that the daily data be the avarage of hourly data.
Also, I have some gap data. I want when there is no data in a specific hour, the code does not consider that especific time and just avarage the rest of that 24 hours to convert to avarage daily data.

1 comentario

Armin Azad
Armin Azad el 9 de Dic. de 2021
I would be more than gratful if you could help me for that

Iniciar sesión para comentar.

Respuestas (1)

Star Strider
Star Strider el 10 de Dic. de 2021
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/829100/Norwalk2_012095493_ready.xlsx', 'VariableNamingRule','preserve')
T1 = 104445×2 table
datetime discharge ____________________ _________ 01-Jan-2010 00:30:00 11.4 01-Jan-2010 01:30:00 11.4 01-Jan-2010 02:30:00 11.1 01-Jan-2010 03:30:00 9.74 01-Jan-2010 04:30:00 10.1 01-Jan-2010 05:30:00 10.1 01-Jan-2010 06:30:00 9.74 01-Jan-2010 07:30:00 10.1 01-Jan-2010 08:30:00 10.4 01-Jan-2010 09:30:00 10.4 01-Jan-2010 10:30:00 9.12 01-Jan-2010 11:30:00 9.74 01-Jan-2010 12:30:00 9.43 01-Jan-2010 13:30:00 10.1 01-Jan-2010 14:30:00 9.74 01-Jan-2010 15:30:00 9.43
TT1 = table2timetable(T1)
TT1 = 104445×1 timetable
datetime discharge ____________________ _________ 01-Jan-2010 00:30:00 11.4 01-Jan-2010 01:30:00 11.4 01-Jan-2010 02:30:00 11.1 01-Jan-2010 03:30:00 9.74 01-Jan-2010 04:30:00 10.1 01-Jan-2010 05:30:00 10.1 01-Jan-2010 06:30:00 9.74 01-Jan-2010 07:30:00 10.1 01-Jan-2010 08:30:00 10.4 01-Jan-2010 09:30:00 10.4 01-Jan-2010 10:30:00 9.12 01-Jan-2010 11:30:00 9.74 01-Jan-2010 12:30:00 9.43 01-Jan-2010 13:30:00 10.1 01-Jan-2010 14:30:00 9.74 01-Jan-2010 15:30:00 9.43
TT1dm = retime(TT1,'daily',@(x)mean(x,'omitnan'))
TT1dm = 4352×1 timetable
datetime discharge ___________ _________ 01-Jan-2010 9.8246 02-Jan-2010 NaN 03-Jan-2010 NaN 04-Jan-2010 7.5137 05-Jan-2010 7.1225 06-Jan-2010 6.7246 07-Jan-2010 6.4671 08-Jan-2010 6.2942 09-Jan-2010 5.9283 10-Jan-2010 NaN 11-Jan-2010 NaN 12-Jan-2010 4.5675 13-Jan-2010 4.3863 14-Jan-2010 4.1396 15-Jan-2010 4.1513 16-Jan-2010 4.4896
TT1ds = retime(TT1,'daily',@(x)std(x,'omitnan'));
N = size(TT1dm,1);
dt = TT1dm.datetime;
dts = string(dt);
mv = TT1dm.discharge;
sv = TT1ds.discharge;
xv = 1:numel(dts);
figure
semilogy(xv, mv, '-b')
hold on
plot(xv, mv+(sv/sqrt(N))*1.96, ':r') % Optional
plot(xv, mv-(sv/sqrt(N))*1.96 , ':r') % Optional
hold off
grid
xt = xticks;
xtv = fix(linspace(min(xv), max(xv), numel(xt)));
set(gca, 'XTick',xtv, 'XTickLabel',dts(xtv))
xlim([min(xtv) max(xtv)])
legend('Daily Mean','±1.96 SEM', 'Location','best')
.

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 9 de Dic. de 2021

Respondida:

el 10 de Dic. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by