Cody

# Problem 44416. Sum of adjacent elements in a vector

Solution 1619294

Submitted on 30 Aug 2018 by Srishti Saha
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   Pass
v = randi(10, 1, randi(10)); s = summ(v); assert(length(s) == length(v) - 1)

s = [] v = 4 7 9 9 6 3 append = 11 s = 11 append = 16 s = 11 16 append = 18 s = 11 16 18 append = 15 s = 11 16 18 15 append = 9 s = 11 16 18 15 9 s = 11 16 18 15 9

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

s = [] v = 1 2 3 4 5 6 7 8 9 10 append = 3 s = 3 append = 5 s = 3 5 append = 7 s = 3 5 7 append = 9 s = 3 5 7 9 append = 11 s = 3 5 7 9 11 append = 13 s = 3 5 7 9 11 13 append = 15 s = 3 5 7 9 11 13 15 append = 17 s = 3 5 7 9 11 13 15 17 append = 19 s = 3 5 7 9 11 13 15 17 19 s = 3 5 7 9 11 13 15 17 19

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

s = [] v = 1 2 4 4 5 8 append = 3 s = 3 append = 6 s = 3 6 append = 8 s = 3 6 8 append = 9 s = 3 6 8 9 append = 13 s = 3 6 8 9 13 s = 3 6 8 9 13

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!