Cody

Problem 6. Select every other element of a vector

Solution 476104

Submitted on 21 Jul 2014 by Ryan Grammenos
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.6332 0.6424 0.1128 0.1865 0.2490

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

y = Columns 1 through 9 0.6949 0.5084 0.5249 0.4638 0.2929 0.8056 0.4383 0.6592 0.3116 Columns 10 through 18 0.8147 0.4982 0.7821 0.8605 0.9613 0.2279 0.4472 0.9882 0.6280 Columns 19 through 27 0.6323 0.6624 0.5756 0.1396 0.6786 0.2355 0.3617 0.0888 0.0186 Columns 28 through 36 0.6046 0.8314 0.6645 0.6063 0.6943 0.6236 0.5465 0.6633 0.8966 Columns 37 through 45 0.8616 0.6711 0.6490 0.6130 0.0889 0.9225 0.3605 0.1405 0.0070 Columns 46 through 50 0.1443 0.5905 0.8869 0.1849 0.0435

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