Cody

# Problem 6. Select every other element of a vector

Solution 111005

Submitted on 12 Jul 2012 by Joe
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))

ans = 0.0922 0.4202 0.1736 0.3519 0.4793

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

ans = Columns 1 through 6 0.7302 0.1336 0.9259 0.9332 0.0626 0.0267 Columns 7 through 12 0.0111 0.1476 0.8168 0.2542 0.2410 0.5051 Columns 13 through 18 0.9244 0.4390 0.1833 0.2491 0.0801 0.8504 Columns 19 through 24 0.3656 0.2869 0.2321 0.2241 0.9813 0.8536 Columns 25 through 30 0.4720 0.0834 0.0556 0.2592 0.0406 0.4494 Columns 31 through 36 0.9024 0.2329 0.2201 0.6702 0.7736 0.2494 Columns 37 through 42 0.8003 0.0058 0.5612 0.4596 0.1378 0.6689 Columns 43 through 48 0.3697 0.3179 0.8287 0.4742 0.6795 0.6454 Columns 49 through 50 0.2948 0.7943

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))

ans = Aogiegiaaayafrwy