Cody

Problem 6. Select every other element of a vector

Solution 1981820

Submitted on 18 Oct 2019 by Gianvito Sylos Labini
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.8095 0.3786 0.1149 0.0255 0.3222

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.6103 0.3895 0.6352 0.6411 0.5293 0.2975 0.8886 0.4764 0.6422 0.9298 0.4329 0.1836 0.3757 0.8167 0.2276 0.7379 0.4291 0.2663 Columns 19 through 36 0.6238 0.7815 0.8294 0.5393 0.2631 0.6276 0.6218 0.9592 0.5393 0.1954 0.0675 0.5193 0.2420 0.4403 0.0689 0.2801 0.9813 0.5672 Columns 37 through 50 0.3909 0.0743 0.0553 0.9360 0.9504 0.2716 0.7277 0.2546 0.8968 0.5514 0.6666 0.3006 0.9038 0.7592

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'