Cody

# Problem 6. Select every other element of a vector

Solution 1287350

Submitted on 15 Oct 2017 by Alexis Marchesi
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))

s = 0.1126 s = 0.1126 0.7562 s = 0.1126 0.7562 0.6988 s = 0.1126 0.7562 0.6988 0.2027 s = 0.1126 0.7562 0.6988 0.2027 0.1991

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

s = 0.0557 s = 0.0557 0.0225 s = 0.0557 0.0225 0.0591 s = 0.0557 0.0225 0.0591 0.9617 s = 0.0557 0.0225 0.0591 0.9617 0.8923 s = 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 s = 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 s = 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 s = 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 s = 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 s = 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 s = 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 s = 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 s = 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 s = 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 s = 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 s = 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 s = 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Column 19 0.1566 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 20 0.1566 0.7463 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 21 0.1566 0.7463 0.7471 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 22 0.1566 0.7463 0.7471 0.3261 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 23 0.1566 0.7463 0.7471 0.3261 0.4845 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 24 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 25 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 26 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 0.1453 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 27 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 0.1453 0.5914 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 28 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 0.1453 0.5914 0.5306 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 29 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 0.1453 0.5914 0.5306 0.6037 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 30 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 0.1453 0.5914 0.5306 0.6037 0.9912 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 31 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 0.1453 0.5914 0.5306 0.6037 0.9912 0.7976 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 32 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 0.1453 0.5914 0.5306 0.6037 0.9912 0.7976 0.2840 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 33 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 0.1453 0.5914 0.5306 0.6037 0.9912 0.7976 0.2840 0.9799 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 34 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 0.1453 0.5914 0.5306 0.6037 0.9912 0.7976 0.2840 0.9799 0.3732 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 35 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 0.1453 0.5914 0.5306 0.6037 0.9912 0.7976 0.2840 0.9799 0.3732 0.9273 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 36 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 0.1453 0.5914 0.5306 0.6037 0.9912 0.7976 0.2840 0.9799 0.3732 0.9273 0.9680 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 36 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 0.1453 0.5914 0.5306 0.6037 0.9912 0.7976 0.2840 0.9799 0.3732 0.9273 0.9680 Column 37 0.3567 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 36 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 0.1453 0.5914 0.5306 0.6037 0.9912 0.7976 0.2840 0.9799 0.3732 0.9273 0.9680 Columns 37 through 38 0.3567 0.5408 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 36 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 0.1453 0.5914 0.5306 0.6037 0.9912 0.7976 0.2840 0.9799 0.3732 0.9273 0.9680 Columns 37 through 39 0.3567 0.5408 0.4575 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 36 0.1566 0.7463 0.7471 0.3261 0.4845 0.8334 0.6347 0.1453 0.5914 0.5306 0.6037 0.9912 0.7976 0.2840 0.9799 0.3732 0.9273 0.9680 Columns 37 through 40 0.3567 0.5408 0.4575 0.6992 s = Columns 1 through 18 0.0557 0.0225 0.0591 0.9617 0.8923 0.5408 0.3066 0.1078 0.6495 0.0891 0.2347 0.8917 0.8433 0.5235 0.9527 0.0774 0.5984 0.4205 Columns 19 through 36 0.1566 0.7463 0.7471 0.32...

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))

s = 'A' s = 'Ao' s = 'Aog' s = 'Aogi' s = 'Aogie' s = 'Aogieg' s = 'Aogiegi' s = 'Aogiegia' s = 'Aogiegiaa' s = 'Aogiegiaaa' s = 'Aogiegiaaay' s = 'Aogiegiaaaya' s = 'Aogiegiaaayaf' s = 'Aogiegiaaayafr' s = 'Aogiegiaaayafrw' s = 'Aogiegiaaayafrwy'

### Community Treasure Hunt

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

Start Hunting!