Cody

Problem 1344. Moving average (variable kernel length)

Solution 551654

Submitted on 2 Jan 2015 by Abdullah Caliskan
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:10; kernel_length=4 y_correct = [ 2.5000 3.5000 4.5000 5.5000 6.5000 7.5000 8.5000]; assert(isequal(moving_avg(x,kernel_length),y_correct))

kernel_length = 4 N = Columns 1 through 9 0.2500 0.7500 1.5000 2.5000 3.5000 4.5000 5.5000 6.5000 7.5000 Columns 10 through 13 8.5000 6.7500 4.7500 2.5000 ans = 2.5000 3.5000 4.5000 5.5000 6.5000 7.5000 8.5000

2   Pass
%% x = 10:20; kernel_length=5 y_correct = [ 12.0000 13.0000 14.0000 15.0000 16.0000 17.0000 18.0000]; assert(isequal(moving_avg(x,kernel_length),y_correct))

kernel_length = 5 N = Columns 1 through 9 2.0000 4.2000 6.6000 9.2000 12.0000 13.0000 14.0000 15.0000 16.0000 Columns 10 through 15 17.0000 18.0000 14.8000 11.4000 7.8000 4.0000 ans = 12 13 14 15 16 17 18

3   Pass
%% x = ones(1,10); kernel_length=5 y_correct = ones(1,6); assert(isequal(moving_avg(x,kernel_length),y_correct))

kernel_length = 5 N = Columns 1 through 9 0.2000 0.4000 0.6000 0.8000 1.0000 1.0000 1.0000 1.0000 1.0000 Columns 10 through 14 1.0000 0.8000 0.6000 0.4000 0.2000 ans = 1 1 1 1 1 1

Community Treasure Hunt

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

Start Hunting!