Cody

Problem 6. Select every other element of a vector

Solution 195045

Submitted on 22 Jan 2013 by Julien
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.2187 0.6915 0.3596 0.3022 0.7961

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

ans = Columns 1 through 10 0.7912 0.7395 0.9498 0.0196 0.9118 0.0713 0.0944 0.9155 0.0520 0.6912 Columns 11 through 20 0.8959 0.2320 0.8497 0.6622 0.8362 0.6506 0.1107 0.0164 0.9057 0.6442 Columns 21 through 30 0.6206 0.6458 0.6189 0.6692 0.4579 0.5231 0.7234 0.5907 0.5077 0.2909 Columns 31 through 40 0.1419 0.5931 0.4706 0.7572 0.6196 0.4211 0.4888 0.8329 0.1027 0.8208 Columns 41 through 50 0.6494 0.7107 0.9586 0.5601 0.4831 0.3085 0.3435 0.5162 0.5766 0.2485

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