David
Farruggio

MathGenie

movsum

Moving sum

Syntax and Description

movsum(A,k) returns an array of local k-point sums, where each sum is calculated over a sliding window of length k across neighboring elements of A. When k is odd, the window is centered about the element in the current position. When k is even, the window is centered about the current and previous elements. The window size is automatically truncated at the endpoints when there are not enough elements to fill the window. When the window is truncated, the sum is taken over only the elements that fill the window. M is the same size as A.
  • If A is a vector, then movsum operates along the length of the vector.
  • If A is a multidimensional array, then movsum operates along the first array dimension whose size does not equal 1.
movsum(A,[kb kf]) computes the sum with a window of length kb+kf+1 that includes the element in the current position, kb elements backward, and kf elements forward.
movsum(___,dim) returns the array of sliding sums along dimension dim for any of the previous syntaxes. For example, if A is a matrix, then movsum(A,k,2) operates along the columns of A, computing the k-element sliding sum for each row.

Back to functions