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.