Problem 44844. Moving average
A moving average function that returns an array that is equal in length to the input arrays (which can be row or column)
A variable window size, w, whenever possible, i.e.
w = 3;
means to use 3 data points on both sides of the point of interest (averaging 7 points total)
returns a ROW vector of moving average values
The following inputs:
x = [1,2,3,4]; y = [3,5,7,9]; w = 2;
should output:
ys = [3,5,7,9];
The following inputs:
x = [1,2,3,4,5]; y = [2,5.5,6,9.5,10]; w = 3;
should output:
ys = [2,4.5,6.6,8.5,10];
Note: the last test case is meant to be a challenge...
Solution Stats
Problem Comments
-
2 Comments
Tip: the x vector is useless, and the standard function movmean will not help since we have a window of variable size.
The problem statement is not very clear, but what this problem is asking you to do is compute a moving average where the desired window size is w elements on either side, and where the window shrinks near the edges of the input vector (while staying symmetric) in order to avoid extending beyond the endpoints of said vector.
Also, as @Rafael observed, the vector x is unnecessary and can be ignored; you're only working with y (and w).
Solution Comments
Show commentsProblem Recent Solvers5
Suggested Problems
-
Count from 0 to N^M in base N.
235 Solvers
-
Project Euler: Problem 3, Largest prime factor
1431 Solvers
-
79 Solvers
-
Find the maximum number of decimal places in a set of numbers
2854 Solvers
-
Generate a string like abbcccddddeeeee
263 Solvers
More from this Author1
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!