Cody

Problem 6. Select every other element of a vector

Solution 2529165

Submitted on 12 Jun 2020 by Bedirhan Güleç
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
x = rand(1,10); actual = everyOther(x); expected = x(1:2:length(x)); assert(isequal(actual, expected))

jj = 2 jj = 3 jj = 4 jj = 5 jj = 6

2   Pass
x = rand(1,100); actual = everyOther(x); expected = x(1:2:length(x)); assert(isequal(actual, expected))

jj = 2 jj = 3 jj = 4 jj = 5 jj = 6 jj = 7 jj = 8 jj = 9 jj = 10 jj = 11 jj = 12 jj = 13 jj = 14 jj = 15 jj = 16 jj = 17 jj = 18 jj = 19 jj = 20 jj = 21 jj = 22 jj = 23 jj = 24 jj = 25 jj = 26 jj = 27 jj = 28 jj = 29 jj = 30 jj = 31 jj = 32 jj = 33 jj = 34 jj = 35 jj = 36 jj = 37 jj = 38 jj = 39 jj = 40 jj = 41 jj = 42 jj = 43 jj = 44 jj = 45 jj = 46 jj = 47 jj = 48 jj = 49 jj = 50 jj = 51

3   Pass
x = ['A' 'long' 'time' 'ago' 'in' 'a' 'galaxy' 'far' 'far' 'away']; actual = everyOther(x); expected = x(1:2:length(x)); assert(isequal(actual, expected))

jj = 2 jj = 3 jj = 4 jj = 5 jj = 6 jj = 7 jj = 8 jj = 9 jj = 10 jj = 11 jj = 12 jj = 13 jj = 14 jj = 15 jj = 16 jj = 17

Suggested Problems

More from this Author95

Community Treasure Hunt

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

Start Hunting!