Cody

# Problem 44416. Sum of adjacent elements in a vector

Solution 2730795

Submitted on 23 Jul 2020
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
filetext = fileread('summ.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')

2   Fail
v = randi(10, 1, randi(10)); s = summ(v); assert(length(s) == length(v) - 1)

Array indices must be positive integers or logical values. Error in summ (line 2) s = v(i) + v(i+1); Error in Test2 (line 2) s = summ(v);

3   Fail
v = 1:10; s_correct = 3:2:19; assert(isequal(summ(v),s_correct))

Array indices must be positive integers or logical values. Error in summ (line 2) s = v(i) + v(i+1); Error in Test3 (line 3) assert(isequal(summ(v),s_correct))

4   Fail
v = [1; 2; 4; 4; 5; 8]; s_correct = [3; 6; 8; 9; 13]; assert(isequal(summ(v),s_correct))

Array indices must be positive integers or logical values. Error in summ (line 2) s = v(i) + v(i+1); Error in Test4 (line 3) assert(isequal(summ(v),s_correct))