Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Problem 429. function on a moving window

Created by Yvan Lengwiler

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.

Problem Group

Solution Statistics

32 correct solutions 21 incorrect solutions
Last solution submitted on Jan 28, 2014