Calculating daily average curve from weekly data

So i have a big timetable with multiple observation from time period of one week. resolution is one hour I want to shrink it into one day time period and same 1 hour resolution. The one thing that could work is to first calculate observation averages so that the table becomes 168*1 and do a for loop to split every day of week into own columns (24*7 table) and then caculate the averages again so i finally get 24*1 table. Is there a better way to do this? timetable default "mean" function doesn't work for this because "hourly" returns only average of observations, but doesn't shrink my weekly data to daily average.

7 Comments

"resolution is one hour I want to shrink it into one day time period and same 1 hour resolution"
what does this mean?
"..."hourly" returns only average of observations, but doesn't shrink my weekly data to daily average."
of course 'hourly' does not give you daily average. Have you tried 'daily'?
Yeah i think i explained that quite poorly. What I mean, is that I want to calculate average value for every hour of the day. So if my data is from one week(24*7=168 hours) i want to get 24 averaged values. The 'daily' just gives me one averaged value for each day, totally 7 days, when i want averaged values for every hour, for 1 day.
So basically i want to transform hourly values of one week to hourly values of one day, and every new hourly value is average of 7 hourly values of every day of the week.
So this code does what i want, but there might be a better way
%% g1; %% this is my original 168*10 matrix
g1=mean(g1,2); %%calculating average of every row, when columns are the observations
k=1;
for i=1:168
for j=1:7
g1m(k,j)=g1(i);
k=k+1;
if k==25
k=1;
continue
end
end
end
g1m=mean(g1m,2); %%final 24*1 matrix
And there i have the average values. Even this is very simple, I i find it difficult to explain what I am doing, making it also difficult to google the solution..
jonas
jonas on 6 Aug 2020
Edited: jonas on 6 Aug 2020
Perhaps this is what you want?
https://nl.mathworks.com/matlabcentral/answers/562451-daily-average-of-several-years-data
... but with hours instead of days
That looks right, thank you! If I understood correctly, I need to do some kind of 1 2...24 1 2.. indexing for that? So normal datevector with Y/M/D/H/M/S doesn't really work there..?
If you provide a small set of data then I could write some example code. Regardless of method, I would strongly suggest using a timetable as basis.
Thank you, I already managed to solve this problem with your suggestion and that kind of indexing what i proposed. The answer by Antonio also works well. I process this data in multiple ways, so I find it easier to just use it as an array and cell array, and store the time data as a separate vector.

Sign in to comment.

 Accepted Answer

If i don't get wrong, it seems that you want to perform this operation:
%% Mean along 10 columns
g1m = mean(g1,2);
%% Reshape to get a the desired size
g1m_w = reshape(g1m,[24 7]);
%% Perform the mean again
g1m = mean(g1m_w,2);

1 Comment

This works very well also. I have no idea why 'reshape' didn't come to my mind from the very beginning.

Sign in to comment.

More Answers (0)

Asked:

on 6 Aug 2020

Commented:

on 8 Aug 2020

Community Treasure Hunt

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

Start Hunting!