Cody

Problem 6. Select every other element of a vector

Solution 1171196

Submitted on 25 Apr 2017 by Barrie Cooper
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.2305 0.7368 0.0150 0.0566 0.3952

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.6590 0.8874 0.0382 0.5149 0.0891 0.4216 0.3262 0.3723 0.3257 0.8322 0.0884 0.7766 0.7064 0.1783 0.6143 0.2688 0.4420 Columns 18 through 34 0.4084 0.0106 0.6439 0.5309 0.6691 0.5941 0.1913 0.6607 0.0368 0.2901 0.0369 0.1592 0.2926 0.1039 0.3460 0.6687 0.7121 Columns 35 through 50 0.2950 0.2400 0.4468 0.7290 0.8142 0.0913 0.5999 0.7994 0.1240 0.1741 0.5115 0.0492 0.4366 0.5676 0.4322 0.5522

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'