Cody

Problem 6. Select every other element of a vector

Solution 70681

Submitted on 4 Apr 2012 by Pavel
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.5129 0.6364 0.7604 0.0112 0.9320

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

y = Columns 1 through 6 0.6419 0.4477 0.9649 0.6491 0.8802 0.4389 Columns 7 through 12 0.2946 0.4431 0.1157 0.1956 0.6875 0.0768 Columns 13 through 18 0.5459 0.3306 0.5909 0.7944 0.5740 0.5818 Columns 19 through 24 0.4331 0.6535 0.7959 0.9924 0.5029 0.8610 Columns 25 through 30 0.9093 0.2131 0.7551 0.6000 0.0287 0.3103 Columns 31 through 36 0.8177 0.9688 0.5395 0.2329 0.1856 0.3957 Columns 37 through 42 0.5624 0.6413 0.8304 0.2290 0.7280 0.6119 Columns 43 through 48 0.1445 0.1555 0.4608 0.6036 0.9470 0.5984 Columns 49 through 50 0.3534 0.5411

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