Cody

# Problem 6. Select every other element of a vector

Solution 590948

Submitted on 3 Mar 2015 by Joseph Laub
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.9488 i = 2 y = 0.9488 0.3945 i = 3 y = 0.9488 0.3945 0.9614 i = 4 y = 0.9488 0.3945 0.9614 0.1292 i = 5 y = 0.9488 0.3945 0.9614 0.1292 0.0506 i = 6

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

y = 0.6837 i = 2 y = 0.6837 0.4016 i = 3 y = 0.6837 0.4016 0.9966 i = 4 y = 0.6837 0.4016 0.9966 0.1521 i = 5 y = 0.6837 0.4016 0.9966 0.1521 0.3852 i = 6 y = 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 i = 7 y = 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 i = 8 y = 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 i = 9 y = 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 i = 10 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Column 10 0.6650 i = 11 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 11 0.6650 0.3373 i = 12 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 12 0.6650 0.3373 0.1368 i = 13 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 13 0.6650 0.3373 0.1368 0.3009 i = 14 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 14 0.6650 0.3373 0.1368 0.3009 0.4398 i = 15 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 15 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 i = 16 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 16 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 i = 17 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 17 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 i = 18 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 i = 19 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Column 19 0.5428 i = 20 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 20 0.5428 0.2110 i = 21 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 21 0.5428 0.2110 0.3694 i = 22 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 22 0.5428 0.2110 0.3694 0.8499 i = 23 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 23 0.5428 0.2110 0.3694 0.8499 0.6905 i = 24 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 24 0.5428 0.2110 0.3694 0.8499 0.6905 0.9116 i = 25 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 25 0.5428 0.2110 0.3694 0.8499 0.6905 0.9116 0.4681 i = 26 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 26 0.5428 0.2110 0.3694 0.8499 0.6905 0.9116 0.4681 0.9791 i = 27 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 27 0.5428 0.2110 0.3694 0.8499 0.6905 0.9116 0.4681 0.9791 0.7428 i = 28 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 27 0.5428 0.2110 0.3694 0.8499 0.6905 0.9116 0.4681 0.9791 0.7428 Column 28 0.1990 i = 29 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 27 0.5428 0.2110 0.3694 0.8499 0.6905 0.9116 0.4681 0.9791 0.7428 Columns 28 through 29 0.1990 0.5326 i = 30 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 27 0.5428 0.2110 0.3694 0.8499 0.6905 0.9116 0.4681 0.9791 0.7428 Columns 28 through 30 0.1990 0.5326 0.3947 i = 31 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 27 0.5428 0.2110 0.3694 0.8499 0.6905 0.9116 0.4681 0.9791 0.7428 Columns 28 through 31 0.1990 0.5326 0.3947 0.8109 i = 32 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 27 0.5428 0.2110 0.3694 0.8499 0.6905 0.9116 0.4681 0.9791 0.7428 Columns 28 through 32 0.1990 0.5326 0.3947 0.8109 0.2787 i = 33 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 27 0.5428 0.2110 0.3694 0.8499 0.6905 0.9116 0.4681 0.9791 0.7428 Columns 28 through 33 0.1990 0.5326 0.3947 0.8109 0.2787 0.8117 i = 34 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 27 0.5428 0.2110 0.3694 0.8499 0.6905 0.9116 0.4681 0.9791 0.7428 Columns 28 through 34 0.1990 0.5326 0.3947 0.8109 0.2787 0.8117 0.5591 i = 35 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 27 0.5428 0.2110 0.3694 0.8499 0.6905 0.9116 0.4681 0.9791 0.7428 Columns 28 through 35 0.1990 0.5326 0.3947 0.8109 0.2787 0.8117 0.5591 0.2553 i = 36 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 27 0.5428 0.2110 0.3694 0.8499 0.6905 0.9116 0.4681 0.9791 0.7428 Columns 28 through 36 0.1990 0.5326 0.3947 0.8109 0.2787 0.8117 0.5591 0.2553 0.4117 i = 37 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 27 0.5428 0.2110 0.3694 0.8499 0.6905 0.9116 0.4681 0.9791 0.7428 Columns 28 through 36 0.1990 0.5326 0.3947 0.8109 0.2787 0.8117 0.5591 0.2553 0.4117 Column 37 0.9526 i = 38 y = Columns 1 through 9 0.6837 0.4016 0.9966 0.1521 0.3852 0.0506 0.5707 0.0063 0.7961 Columns 10 through 18 0.6650 0.3373 0.1368 0.3009 0.4398 0.5088 0.5626 0.4733 0.3974 Columns 19 through 27 0.5428 0.2110 0.3694 0.8499 0.6905 0.9116 0.4681 0.9791 0.7428 Columns 28...

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 = A i = 2 y = Ao i = 3 y = Aog i = 4 y = Aogi i = 5 y = Aogie i = 6 y = Aogieg i = 7 y = Aogiegi i = 8 y = Aogiegia i = 9 y = Aogiegiaa i = 10 y = Aogiegiaaa i = 11 y = Aogiegiaaay i = 12 y = Aogiegiaaaya i = 13 y = Aogiegiaaayaf i = 14 y = Aogiegiaaayafr i = 15 y = Aogiegiaaayafrw i = 16 y = Aogiegiaaayafrwy i = 17