Cody

Problem 6. Select every other element of a vector

Solution 195087

Submitted on 22 Jan 2013 by Idono
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.2113 0.8922 0.9843 0.7437 0.9978

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.4272 0.8519 0.2842 0.7741 0.4771 0.3917 0.3970 0.4285 0.6297 0.7774 Columns 11 through 20 0.0105 0.9933 0.6031 0.5133 0.9254 0.5382 0.9738 0.1851 0.0126 0.3496 Columns 21 through 30 0.7447 0.2558 0.1693 0.7461 0.4412 0.6099 0.0483 0.7691 0.9007 0.4830 Columns 31 through 40 0.2739 0.3113 0.9043 0.6106 0.9015 0.9745 0.5164 0.9963 0.9721 0.8128 Columns 41 through 50 0.9018 0.7486 0.8844 0.3002 0.1514 0.1247 0.0888 0.3881 0.9898 0.7374

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