Cody

# Problem 6. Select every other element of a vector

Solution 1386923

Submitted on 20 Dec 2017 by Bailey Horton
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))

n = 10 indices = 1 2 3 4 5 6 7 8 9 10 y = 0 0 0 0 0 y = 0.0502 0 0 0 0 y = 0.0502 0.9535 0 0 0 y = 0.0502 0.9535 0.9240 0 0 y = 0.0502 0.9535 0.9240 0.5641 0 y = 0.0502 0.9535 0.9240 0.5641 0.4861

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

n = 100 indices = Columns 1 through 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Columns 31 through 60 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 Columns 61 through 90 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 Columns 91 through 100 91 92 93 94 95 96 97 98 99 100 y = Columns 1 through 30 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 19 through 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 37 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0.8430 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 19 through 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 37 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0.8430 0.9209 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 19 through 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 37 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0.8430 0.9209 0.5762 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 19 through 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 37 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0.8430 0.9209 0.5762 0.9297 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 19 through 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 37 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0.8430 0.9209 0.5762 0.9297 0.4482 0 0 0 0 0 0 0 0 0 0 0 0 Columns 19 through 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 37 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0.8430 0.9209 0.5762 0.9297 0.4482 0.2289 0 0 0 0 0 0 0 0 0 0 0 Columns 19 through 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 37 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0.8430 0.9209 0.5762 0.9297 0.4482 0.2289 0.9944 0 0 0 0 0 0 0 0 0 0 Columns 19 through 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 37 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0.8430 0.9209 0.5762 0.9297 0.4482 0.2289 0.9944 0.8195 0 0 0 0 0 0 0 0 0 Columns 19 through 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 37 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0.8430 0.9209 0.5762 0.9297 0.4482 0.2289 0.9944 0.8195 0.6930 0 0 0 0 0 0 0 0 Columns 19 through 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 37 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0.8430 0.9209 0.5762 0.9297 0.4482 0.2289 0.9944 0.8195 0.6930 0.7583 0 0 0 0 0 0 0 Columns 19 through 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 37 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0.8430 0.9209 0.5762 0.9297 0.4482 0.2289 0.9944 0.8195 0.6930 0.7583 0.0515 0 0 0 0 0 0 Columns 19 through 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 37 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0.8430 0.9209 0.5762 0.9297 0.4482 0.2289 0.9944 0.8195 0.6930 0.7583 0.0515 0.2176 0 0 0 0 0 Columns 19 through 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 37 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0.8430 0.9209 0.5762 0.9297 0.4482 0.2289 0.9944 0.8195 0.6930 0.7583 0.0515 0.2176 0.6119 0 0 0 0 Columns 19 through 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 37 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0.8430 0.9209 0.5762 0.9297 0.4482 0.2289 0.9944 0.8195 0.6930 0.7583 0.0515 0.2176 0.6119 0.5517 0 0 0 Columns 19 through 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 37 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 18 0.4229 0.8430 0.9209 0.5762 0.9297 0.4482 0.2289 0.9944 0.81...

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

n = 31 indices = Columns 1 through 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Column 31 31 y = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = 65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = 65 111 0 0 0 0 0 0 0 0 0 0 0 0 0 y = 65 111 103 0 0 0 0 0 0 0 0 0 0 0 0 y = 65 111 103 105 0 0 0 0 0 0 0 0 0 0 0 y = 65 111 103 105 101 0 0 0 0 0 0 0 0 0 0 y = 65 111 103 105 101 103 0 0 0 0 0 0 0 0 0 y = 65 111 103 105 101 103 105 0 0 0 0 0 0 0 0 y = 65 111 103 105 101 103 105 97 0 0 0 0 0 0 0 y = 65 111 103 105 101 103 105 97 97 0 0 0 0 0 0 y = 65 111 103 105 101 103 105 97 97 97 0 0 0 0 0 y = 65 111 103 105 101 103 105 97 97 97 121 0 0 0 0 y = 65 111 103 105 101 103 105 97 97 97 121 97 0 0 0 y = 65 111 103 105 101 103 105 97 97 97 121 97 102 0 0 y = 65 111 103 105 101 103 105 97 97 97 121 97 102 114 0 y = 65 111 103 105 101 103 105 97 97 97 121 97 102 114 119 y = 65 111 103 105 101 103 105 97 97 97 121 97 102 114 119 121

### Community Treasure Hunt

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

Start Hunting!