How do I change these daily time series data to monthly?

Hello, I have a daily time series data in an array of 81(rows) by 4748 (columns), the 81 rows represents the points at which the data (in their respective corresponding column) was measured (daily). Then I have another arrey of the Time, which is 4748 by 1 (a column matrix) consisting the dates, from January 1, 2005. I need guidance on how to turn these daily time series into monthly. Thank you.

 Réponse acceptée

Walter Roberson
Walter Roberson le 22 Jan 2019
Convert to timetable() objects and use retime()

11 commentaires

Abubakar Sani-Mohammed
Abubakar Sani-Mohammed le 23 Jan 2019
Modifié(e) : Abubakar Sani-Mohammed le 23 Jan 2019
Thanks for your response, I tried applying your direction but it returns an error, saying " undefined function or variable 'timetable' ". what should I do please? Does it mean my version of Matlab (R2016a) doesn't support that function?
timetable objects were introduced in R2016b.
When you convert the daily data into monthly, do you want to take montly totals or montly averages ?
wow, I see, Thanks very much Walter Roberson. I would like to take the montly averages Sir.
Are your Time in datetime format or in datenum format?
Hello Walter Roberson, Yes Sir, it is in datenum format. it starts from the year 2005 to 2018. I have attached the data (HYDL.mat), it contains the Times and the variables. Thank you very much for your effort.
dv = datevec(datenum(years(Time) ));
monthnum = dv(:,1)*12 + dv(:,2);
relmonth = monthnum - min(monthnum) + 1;
nummonth = max(relmonth);
numpoints = size(duVq_hydl,1);
summarized = zeros(numpoints, nummonth);
for pointnum = 1 : numpoints
summarized(pointnum, :) = accumarray( relmonth, duVq_hydl(pointnum, :).', [], @mean );
end
In theory you should be able to get away without the datenum() in the first line, but I found a bug in datevec() that this is a work-around for.
Abubakar Sani-Mohammed
Abubakar Sani-Mohammed le 27 Jan 2019
Modifié(e) : Abubakar Sani-Mohammed le 27 Jan 2019
Hello Walter Roberson, I really appreciate your time and effort. Very impactful. Thank you very much. This works but Please one more challenge, Now, summatized(pointnum, :) will have an 81 by 157 matrix, but the vector time has not changed, which should be a 157 by 1 matrix. because if I want to plot each row (81 by 157), the corresponding time wouldnt be same. your guide would be appreciated.
Awk! I just noticed another MATLAB bug in the date conversion.
Question:
Your values appear to be expressed in full years and fractions of a year. But are those fractions expressed in fixed length 365 day years, or in fixed length 365.249 day years, or are they relative to the number of full days in the year?
My tests suggest that they are most likely relative to the number of full days in the year.
... would it be okay to take the shortcut of assuming that the times are noon every day from Jan 1 2004 to December 31, 2017 ?
Yes Sir, your test is right and as such your assumption can hold. Thank you.
dv = datevec(datenum('2005/01/01 12:00'):datenum('2017/12/31 12:00'));
monthnum = dv(:,1)*12 + dv(:,2);
relmonth = monthnum - monthnum(1) + 1;
nummonth = relmonth(end);
numpoints = size(duVq_hydl,1);
summarized = zeros(numpoints, nummonth);
for pointnum = 1 : numpoints
summarized(pointnum, :) = accumarray( relmonth, duVq_hydl(pointnum, :).', [], @mean );
end
summary_dates = datenum(2005, 1:nummonth, 1);
This is 156 months, not 157 months.
You were not clear as to what date format you wanted the summary dates to be, so I used serial date numbers.
Thank you very much, I will work around it. I really appreciate your time and effort.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by