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 415168

Submitted on 8 Mar 2014 by Alfonso Nieto-Castanon

Correct

22Size
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 3 5 7];
y_correct = [1 2 1 -2];
assert(isequal(CumDiff(x),y_correct))

                    
2
Pass
 
%%
x = [23 3 15 16];
y_correct = [23 -20 -11 -25];
assert(isequal(CumDiff(x),y_correct))

                    
3
Pass
 
%%
x = [5];
y_correct = [5];
assert(isequal(CumDiff(x),y_correct))

                    
4
Pass
 
%%
x = 43:49;
y_correct = [ 43   1   -42   -86    -131   -177   -224];
assert(isequal(CumDiff(x),y_correct))

                    
5
Pass
 
%%
x = zeros(0,1);
y_correct = zeros(0,1)
assert(isequal(CumDiff(x),y_correct))
y_correct =
   Empty matrix: 0-by-1
6
Pass
 
%%
x = [1 10 100 1000 10000];
y_correct = [1 9 89 889 8889];
assert(isequal(CumDiff(x),y_correct))