Cody

Problem 6. Select every other element of a vector

Solution 1851322

Submitted on 17 Jun 2019 by Z Liang
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.1087 0.8684 0.5899 0.7134 0.3399

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.2024 0.5950 0.6353 0.4679 0.6646 0.1836 0.3391 0.2584 0.6841 0.0334 0.9240 0.8436 0.8067 0.2639 0.8891 0.7464 0.4671 Columns 18 through 34 0.6286 0.2723 0.9827 0.0402 0.7217 0.8040 0.8018 0.1412 0.5107 0.8357 0.3630 0.8084 0.0163 0.3840 0.7385 0.1722 0.2125 Columns 35 through 50 0.8499 0.4085 0.9074 0.4129 0.6156 0.9085 0.7927 0.5509 0.0650 0.9676 0.0622 0.0058 0.2137 0.1619 0.1368 0.3344

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!