Cody

# Problem 6. Select every other element of a vector

Solution 203405

Submitted on 13 Feb 2013 by Zackary
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.950812566335003 0.848758097124406 0.710280637869411 0.693531636597079 0.969938423218391

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

ans = Columns 1 through 5 0.455680613900626 0.840003863992062 0.306561197723627 0.998063178846787 0.255246347711504 Columns 6 through 10 0.236787862787544 0.057998592022932 0.235777827793703 0.477732768525222 0.877857542602293 Columns 11 through 15 0.524520111919891 0.309071274013884 0.508513663227937 0.372658457501257 0.295334906924446 Columns 16 through 20 0.401481257869821 0.583527895698722 0.710393437470929 0.858897066497353 0.559472988671573 Columns 21 through 25 0.282365853339939 0.999454313667583 0.153231804433259 0.614353643203440 0.639885193417812 Columns 26 through 30 0.778703660493727 0.860307982746475 0.081880260412075 0.212933848184829 0.739629084456045 Columns 31 through 35 0.173232068018396 0.090781365505420 0.150929458677782 0.833917529344185 0.912355478085261 Columns 36 through 40 0.452589021338764 0.226580331249974 0.864483988359714 0.917270395942067 0.183212185718489 Columns 41 through 45 0.127264029626087 0.193428878879864 0.540320498550618 0.710663737058869 0.769222314121059 Columns 46 through 50 0.414839576559892 0.416126486309420 0.291398875437924 0.811911881537764 0.377938249468331

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

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!