Cody

Problem 6. Select every other element of a vector

Solution 1141844

Submitted on 20 Mar 2017 by Dongdong Yue
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))

i = 1 3 5 7 9 y = 0.4163 0.8679 0.7386 0.1474 0.4786

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

i = Columns 1 through 29 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 Columns 30 through 50 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 y = Columns 1 through 17 0.4357 0.3571 0.7796 0.7595 0.7792 0.3516 0.8399 0.1786 0.6771 0.2112 0.0753 0.2959 0.2741 0.7981 0.0787 0.0911 0.9761 Columns 18 through 34 0.8480 0.0238 0.6164 0.5231 0.7537 0.0766 0.8916 0.9377 0.8856 0.9897 0.8924 0.7978 0.0340 0.8050 0.7513 0.4725 0.0594 Columns 35 through 50 0.9255 0.0239 0.7362 0.0626 0.0477 0.4504 0.6290 0.1318 0.8489 0.4908 0.6703 0.8747 0.8196 0.1950 0.6220 0.1241

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))

i = 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 y = 'Aogiegiaaayafrwy'

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!