Cody

# Problem 6. Select every other element of a vector

Solution 110027

Submitted on 11 Jul 2012 by M Kyweriga
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 = Columns 1 through 3 0.178818180180418 0.529477852047439 0.708611123517702 Columns 4 through 5 0.192051525090967 0.250568976454616

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

ans = Columns 1 through 3 0.317117972613391 0.627007749338177 0.746645084721752 Columns 4 through 6 0.746163343499319 0.326062508228738 0.304590755269240 Columns 7 through 9 0.872433801354290 0.586974153574840 0.936908956033066 Columns 10 through 12 0.294474850124343 0.425880598462250 0.766897502805414 Columns 13 through 15 0.717856273794243 0.345780325606777 0.507434504527840 Columns 16 through 18 0.694308385952086 0.397198094690175 0.518511698710961 Columns 19 through 21 0.478933385490393 0.354234580898406 0.102253963689976 Columns 22 through 24 0.592601686963012 0.703187407397462 0.562623739116948 Columns 25 through 27 0.393284707632936 0.517842484778558 0.513017818035368 Columns 28 through 30 0.746004488508414 0.998529035410832 0.603541454998696 Columns 31 through 33 0.896778738672533 0.876851970442988 0.212711270141302 Columns 34 through 36 0.871165921377759 0.465188042658727 0.459195814396671 Columns 37 through 39 0.478286801985922 0.270446740917570 0.354346872965678 Columns 40 through 42 0.242544419143663 0.966569599363552 0.771912916577377 Columns 43 through 45 0.787269908728969 0.533574307029301 0.552982713840280 Columns 46 through 48 0.003347219634409 0.896214031306959 0.897082713331303 Columns 49 through 50 0.793639283660969 0.055058779986846

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!