I have this function that performs the monthly sum of the days of the months, that is, from the 1st to the 31st of January 2000, it adds up the data referring to these days of the month. It is like this for the other months and the other years until 2021.
My goal is to perform the sum of Januarys, Februarys, March and so on for the rest of the months of the year.
For example:
Jan 2000 + Jan 2001 + Jan 2002 + ... Jan 2021 = TOTAL OF ALL JANUARY
Feb 2000 + Feb 2001 + Feb 2002 + ... Feb 2021 = TOTAL OF ALL FEBRUARY
.
.
.
Dec 2000 + Dec 2001 + Dec 2002 + ... Dec 2021 = TOTAL OF ALL DECEMBER
If anyone has any ideas, I'd be very grateful!
function Y = monthly_sum(T, X)
grp = [datenum(2000, 1:252, 1), Inf];
TX = X(T >= grp(i) & T < grp(i+1), j);
X_hour(i,j) = nansum(TX);
Y = [grp(1:ngrp).', X_hour];