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 131450

Submitted on 27 Aug 2012 by Aurelien Queffurust

Correct

14Size
This is the leading solution.
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]))))
{Warning: Function /users/msssystem4/assert.m has the same
name as a MATLAB builtin. We suggest you rename the function
to avoid a potential name conflict.}
{> In mopt at 3
  In verifyCode>evaluateCode at 189
  In verifyCode at 40
  In fevalJSON at 14}
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))))
{Warning: Function /users/msssystem4/assert.m has the same
name as a MATLAB builtin. We suggest you rename the function
to avoid a potential name conflict.}
{> In mopt at 3
  In verifyCode>evaluateCode at 189
  In verifyCode at 40
  In fevalJSON at 14}
3
Pass
 
%%
x = rand(1,10);
y_correct = x;
y = mopt(@mean,x,0,0);
assert(isequal(y,y_correct))
{Warning: Function /users/msssystem4/assert.m has the same
name as a MATLAB builtin. We suggest you rename the function
to avoid a potential name conflict.}
{> In mopt at 3
  In verifyCode>evaluateCode at 189
  In verifyCode at 40
  In fevalJSON at 14}