Cody

Problem 429. function on a moving window

Solution 1407112

Submitted on 6 Jan 2018 by Thomas Steffen
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
x = 1:6; y = mopt(@mean,x,1,2); y_correct = [NaN 2.5000 3.5000 4.5000 NaN NaN]; assert(isequal(y(2:end-2),y_correct(2:end-2)) && all(isnan(y([1,5,6]))))

filtered = NaN 2.5000 3.5000 4.5000 NaN NaN

2   Pass
x = [0.2 0.8 0.7 1.1 1.1 1.0 0.2]; y = mopt(@std,x,2,0); y_correct = [NaN NaN 0.321455025366432 0.208166599946613 0.23094010767585 0.0577350269189626 0.493288286231625]; assert(max(abs(y_correct(3:end)-y(3:end)))<2*eps && all(isnan(y(1:2))))

filtered = NaN NaN 0.3215 0.2082 0.2309 0.0577 0.4933

3   Pass
x = rand(1,10); y_correct = x; y = mopt(@mean,x,0,0); assert(isequal(y,y_correct))

filtered = 0.4384 0.6232 0.0973 0.1962 0.5934 0.8124 0.9840 0.8986 0.9365 0.6486

Suggested Problems

More from this Author1

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!