Problem 429. function on a moving window
Create a function that applies an operation (such as @sum, @mean, @std, @norm etc) to a moving window of the data.
First example:
filtered = mopt(@mean,1:6,1,2)
Then filtered = [NaN 2.5000 3.5000 4.5000 NaN NaN]
This is the moving average.
Second example:
filtered = mopt(@std,[0.2 0.8 0.7 1.1 1.1 1.0 0.2],2,0)
Then filtered = [NaN NaN 0.3215 0.2082 0.2309 0.0577 0.4933]
This is the 'moving standard error'.
The first arg of mopt is a function handle. It must be a function that takes a vector as input and produces a scalar as output.
The second arg is the vector of data.
The third and fourth args are the lags and leads that determin the size of the moving window.
Solution Stats
Problem Comments
-
1 Comment
GeeTwo
on 5 Aug 2022
It wasn't clear until seeing the test cases. The problem is to APPLY the given function handle and return the filtered data, NOT to return a function handle that will do this.
Solution Comments
Show commentsProblem Recent Solvers47
Suggested Problems
-
1629 Solvers
-
166 Solvers
-
Project Euler: Problem 3, Largest prime factor
1430 Solvers
-
285 Solvers
-
Generate a random matrix A of (1,-1)
313 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!