Borrar filtros
Borrar filtros

Function for Calculating Moving sum

3 visualizaciones (últimos 30 días)
John
John el 16 de Jul. de 2012
Comentada: Image Analyst el 12 de Oct. de 2017
Is there any function to calculate moving sum of a vector? I use "smooth" for calculating the moving average of a vector
  1 comentario
F.
F. el 16 de Jul. de 2012
I'm sorry but I don't understand "moving sum of a vector" ... Could you explain it and give a little exemple ? thanks

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 16 de Jul. de 2012
Editada: Image Analyst el 16 de Jul. de 2012
For a "moving" sum - the sum in a window - you can use conv(), or conv2() in two dimensions:
windowWidth = 15; % or whatever.
movingSum = conv(oneDsignal, ones(1, windowWidth));
for the moving average:
windowWidth = 15; % or whatever.
movingAverage = conv(oneDsignal, ones(1, windowWidth) / windowWidth);
  4 comentarios
Tina Fuhrmann
Tina Fuhrmann el 11 de Oct. de 2017
Why does it work with conv?
Image Analyst
Image Analyst el 12 de Oct. de 2017
Why wouldn't it? If you replace each element with the average of elements around it, which is what conv() can do, then that's the moving average.

Iniciar sesión para comentar.

Más respuestas (1)

Jonathan Sullivan
Jonathan Sullivan el 16 de Jul. de 2012
help filter
doc filter
Example: Take a 10 element moving average.
x = rand(1e3,1);
n = 10;
x_moving_average = filter(ones(1,n)/n,1,x);

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by