Cody

# Problem 6. Select every other element of a vector

Solution 2000400

Submitted on 3 Nov 2019 by Pravallika T
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.8353 0.5841 0.8012 0.8360 0.3496

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

i = Columns 1 through 30 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 59 Columns 31 through 50 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 y = Columns 1 through 18 0.9355 0.9053 0.2024 0.0229 0.6650 0.4902 0.1331 0.0219 0.3196 0.6224 0.0848 0.2817 0.4419 0.0063 0.2124 0.7625 0.0486 0.1556 Columns 19 through 36 0.2748 0.1086 0.0222 0.1455 0.2891 0.0437 0.5837 0.9521 0.3449 0.1012 0.8942 0.5152 0.6057 0.6722 0.5183 0.2714 0.8391 0.2002 Columns 37 through 50 0.6912 0.3133 0.7713 0.5075 0.8556 0.9577 0.0926 0.7037 0.7051 0.7042 0.0033 0.9691 0.2924 0.2003

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'

### Community Treasure Hunt

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

Start Hunting!