Cody

Problem 6. Select every other element of a vector

Solution 187361

Submitted on 7 Jan 2013 by Vialla
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.7950 0.7934 0.2063 0.1603 0.2619

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.8267 0.0321 0.1217 0.2962 0.4143 0.0486 0.4561 0.1233 0.5316 0.0759 Columns 11 through 20 0.1291 0.2429 0.4236 0.4875 0.4824 0.0660 0.7995 0.2524 0.4444 0.5661 Columns 21 through 30 0.0075 0.8479 0.5322 0.3300 0.3857 0.6639 0.9834 0.3999 0.0438 0.5570 Columns 31 through 40 0.8765 0.8261 0.0056 0.6792 0.0902 0.3091 0.9980 0.7864 0.5925 0.5409 Columns 41 through 50 0.8878 0.8738 0.3584 0.5757 0.2268 0.8430 0.6864 0.5789 0.8730 0.2296

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