Cody

Problem 6. Select every other element of a vector

Solution 1734574

Submitted on 24 Feb 2019 by Travis Zhang
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.6427 0.9272 0.1645 0.1268 0.5565

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

y = Columns 1 through 18 0.6625 0.7383 0.4735 0.9674 0.1981 0.9101 0.6405 0.1650 0.7789 0.9525 0.1241 0.3422 0.3111 0.7767 0.6467 0.8511 0.3228 0.5840 Columns 19 through 36 0.6373 0.8874 0.5931 0.3441 0.1844 0.0075 0.7837 0.4661 0.9559 0.3658 0.1558 0.2847 0.2676 0.5947 0.3859 0.2030 0.0533 0.2969 Columns 37 through 50 0.5869 0.1005 0.3725 0.8791 0.4088 0.9519 0.3189 0.1043 0.6248 0.1538 0.7957 0.3509 0.9540 0.7396

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'