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

Solution 236358

Submitted on 26 Apr 2013 by Mehmet OZC

Correct

42Size
Leading solution size is 12.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
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
y =
    2.5000
y =
    2.5000    3.5000
y =
    2.5000    3.5000    4.5000
y =
    2.5000    3.5000    4.5000    5.5000
y =
    2.5000    3.5000    4.5000    5.5000    6.5000
y =
    2.5000    3.5000    4.5000    5.5000    6.5000    7.5000
y =
    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
y =
    12
y =
    12    13
y =
    12    13    14
y =
    12    13    14    15
y =
    12    13    14    15    16
y =
    12    13    14    15    16    17
y =
    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
y =
     1
y =
     1     1
y =
     1     1     1
y =
     1     1     1     1
y =
     1     1     1     1     1
y =
     1     1     1     1     1     1