How to convert a time serie with daily data to a time serie with weekly data by taking the average of every 7 values of the daily vector?

6 views (last 30 days)
I have a vector with daily data. I need to average every 7 values of it to obtain a new vector with weekly data.
Fernanda Suarez Jaimes
Fernanda Suarez Jaimes on 10 Mar 2020
%Time Vector
xtime1= [1:1:6000]'; %daily
xtime2= [1:1:42000]'; %weekly
%Time Series 1- daily entries
%comand randn generats 42000 random numbers that are normaly distributed.
%generating time series with 6000 entries log-normal distributed
%the code for this distribution is based on the code available at
rng('default'); % So that numbers can be repeated
time_series2 = lognrnd(0,0.25, [6000 1]); %generating time series with mu set to zero and sigma 0.25

Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 11 Mar 2020
As you mentioned in your comment, you have a vector of type double. In that case, you can average 7 elements as follow:
x = rand(1000,1); % random data
x = padarray(x, [ceil(numel(x)/7)*7 - numel(x) 0], 0, 'post'); % make sure that number of elements are multiple of 7
mean_x = mean(reshape(x, 7, []), 1)';

Sign in to comment.

More Answers (1)

Stephan on 10 Mar 2020
Edited: Stephan on 10 Mar 2020
The usual way to do this is by using the retime function.

Community Treasure Hunt

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

Start Hunting!