Cody

Problem 44416. Sum of adjacent elements in a vector

Solution 2251867

Submitted on 3 May 2020 by amir shabso
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)

v1 = 9 8 5 8 6 2 v2 = 10 9 8 5 8 6 s = 19 17 13 13 14 8

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

v1 = 2 3 4 5 6 7 8 9 10 v2 = 1 2 3 4 5 6 7 8 9 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))

v1 = 2 4 4 5 8 v2 = 1 2 4 4 5 s = 3 6 8 9 13

Suggested Problems

More from this Author25

Community Treasure Hunt

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

Start Hunting!