convert hourly data to daily data
Show older comments
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 Comment
Armin Azad
on 9 Dec 2021
Answers (1)
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/829100/Norwalk2_012095493_ready.xlsx', 'VariableNamingRule','preserve')
TT1 = table2timetable(T1)
TT1dm = retime(TT1,'daily',@(x)mean(x,'omitnan'))
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')
.
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!