Cody

Problem 6. Select every other element of a vector

Solution 1993099

Submitted on 28 Oct 2019 by Javier Castellano
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.9312 0.4859 0.2220 0.1526 0.0017

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.6431 0.7649 0.0776 0.2731 0.3238 0.2175 0.6035 0.8076 0.8646 0.7493 0.5732 0.0324 0.0743 0.3908 0.2980 0.8992 0.7404 Columns 18 through 34 0.8132 0.2494 0.1146 0.3825 0.4778 0.2495 0.0984 0.0501 0.5500 0.6420 0.4879 0.0879 0.3616 0.5156 0.0287 0.5755 0.8290 Columns 35 through 50 0.5978 0.5740 0.4862 0.0618 0.1210 0.3608 0.7409 0.2157 0.1101 0.1352 0.2928 0.0800 0.0421 0.0693 0.7879 0.6550

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'