Cody

Problem 6. Select every other element of a vector

Solution 218277

Submitted on 17 Mar 2013 by Votka Vai
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.6286 0.7030 0.9181 0.1552 0.4140

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

y = Columns 1 through 10 0.9088 0.0842 0.3536 0.6736 0.3668 0.1785 0.0918 0.3047 0.4255 0.6278 Columns 11 through 20 0.2014 0.0370 0.8593 0.0466 0.9632 0.0981 0.0956 0.3449 0.1741 0.8416 Columns 21 through 30 0.0831 0.2141 0.1762 0.7146 0.3960 0.0314 0.7969 0.3044 0.8276 0.3387 Columns 31 through 40 0.4375 0.8928 0.3472 0.0151 0.6867 0.3976 0.7015 0.1056 0.2184 0.3700 Columns 41 through 50 0.1256 0.7416 0.8483 0.7226 0.3396 0.8297 0.9721 0.4736 0.1654 0.3244

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