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?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Fernanda Suarez Jaimes
el 10 de Mzo. de 2020
Comentada: Fernanda Suarez Jaimes
el 12 de Mzo. de 2020
I have a vector with daily data. I need to average every 7 values of it to obtain a new vector with weekly data.
2 comentarios
Respuesta aceptada
Ameer Hamza
el 11 de Mzo. de 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)';
3 comentarios
Ameer Hamza
el 12 de Mzo. de 2020
Fernanda, the second x does not need to be the same, your code is correct. But you will get an error because you are giving extra spaces between function name and the input arguments. This is generally not a problem, but it will cause an error when done inside [ ] brackets. So change the third line
time_series3 = padarray (time_series1, [ceil(numel (time_series1) / 7) * 7 - numel(time_series1) 0], 0, 'post' );
Ver también
Categorías
Más información sobre Time Series en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!