How can i create a loop to generate daily averages from a csv. file for over four years and whose data was input at a 15minutes interval?

6 views (last 30 days)
the data looks like this

Accepted Answer

Cris LaPierre
Cris LaPierre on 1 Sep 2022
Edited: Cris LaPierre on 1 Sep 2022
Use groupsummary and group the data by 'monthofyear' and 'dayofmonth' and the method set to mean. See this answer:
Here is a simple example
Date = [datetime(2016,6,4)+calyears(0:5)';datetime(2016,6,5)+calyears(0:5)'];
X = rand(size(Date));
Y = rand(size(Date));
Z = rand(size(Date));
tbl = table(Date,X,Y,Z)
tbl = 12×4 table
Date X Y Z ___________ _______ ________ _______ 04-Jun-2016 0.56436 0.95061 0.63577 04-Jun-2017 0.70903 0.050817 0.74741 04-Jun-2018 0.57119 0.54743 0.12786 04-Jun-2019 0.2342 0.21309 0.78041 04-Jun-2020 0.91886 0.353 0.45837 04-Jun-2021 0.3717 0.70704 0.72707 05-Jun-2016 0.58379 0.70093 0.39723 05-Jun-2017 0.41526 0.26787 0.13649 05-Jun-2018 0.15754 0.93554 0.50168 05-Jun-2019 0.69327 0.69517 0.38602 05-Jun-2020 0.93947 0.75884 0.64675 05-Jun-2021 0.26944 0.37348 0.22696
out = groupsummary(tbl,["Date","Date"],["monthofyear","dayofmonth"],'mean')
out = 2×6 table
monthofyear_Date dayofmonth_Date GroupCount mean_X mean_Y mean_Z ________________ _______________ __________ _______ _______ _______ 6 4 6 0.56156 0.47033 0.57948 6 5 6 0.5098 0.62197 0.38252
  2 Comments
CKJ
CKJ on 1 Sep 2022
Thanks for the support. can you please give me some light about the error which i get when i try to apply the code on my data.
SLRdata=readtable("Gulu.csv","VariableNamingRule","preserve");
SLRdata.Date=datestr(SLRdata.Date,"local");
Tbl=table(SLRdata(:,"Date"),SLRdata(:,"Temperature (°C)"),SLRdata(:,"Relative Humidity (% RH)"),SLRdata(:,"Global Radiation (W/m²)"))
out = groupsummary(Tbl,["Var2","Var3","Var4"],["monthofyear","dayofmonth"],'mean')
CKJ
CKJ on 2 Sep 2022
I was able to corrrect the error by critically analysing the help you had rendered in the first reply. THANKS very # I did not know group summary does the task very well.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!