Cody

Problem 6. Select every other element of a vector

Solution 1959487

Submitted on 4 Oct 2019 by Tomas Mikulic
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))

y = 0.9291 0.3481 0.2865 0.9760 0.3432

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

y = Columns 1 through 17 0.8971 0.1565 0.3383 0.2069 0.6859 0.9665 0.7624 0.9061 0.5514 0.2184 0.8238 0.8676 0.8368 0.6398 0.0689 0.5269 0.7839 Columns 18 through 34 0.5019 0.9399 0.5859 0.4748 0.0420 0.9146 0.3798 0.9239 0.5294 0.3795 0.2993 0.7414 0.8401 0.5682 0.6421 0.6805 0.0219 Columns 35 through 50 0.2318 0.3716 0.3311 0.2740 0.5839 0.7059 0.2165 0.6121 0.2142 0.9807 0.2454 0.8788 0.5838 0.4059 0.6037 0.3147

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

y = 'Aogiegiaaayafrwy'