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

53.85% Correct | 46.15% Incorrect
Last Solution submitted on Feb 10, 2024

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers46

Suggested Problems

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!