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 54635

Submitted on 1 Mar 2012 by S L

Correct

50Size
Leading solution size is 14.
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: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]))))

                    
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))))

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