Cody

# Problem 6. Select every other element of a vector

Solution 539616

Submitted on 3 Dec 2014 by naushad
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 = [] c = 1 y = 0.7527 c = 2 y = 0.7527 0.3802 c = 3 y = 0.7527 0.3802 0.9216 c = 4 y = 0.7527 0.3802 0.9216 0.5865 c = 5 y = 0.7527 0.3802 0.9216 0.5865 0.2624 c = 6

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

y = [] c = 1 y = 0.9714 c = 2 y = 0.9714 0.0858 c = 3 y = 0.9714 0.0858 0.3578 c = 4 y = 0.9714 0.0858 0.3578 0.5968 c = 5 y = 0.9714 0.0858 0.3578 0.5968 0.5092 c = 6 y = 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 c = 7 y = 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 c = 8 y = 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 c = 9 y = 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 c = 10 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Column 10 0.4245 c = 11 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 11 0.4245 0.1573 c = 12 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 12 0.4245 0.1573 0.6956 c = 13 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 13 0.4245 0.1573 0.6956 0.9420 c = 14 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 14 0.4245 0.1573 0.6956 0.9420 0.2193 c = 15 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 15 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 c = 16 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 16 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 c = 17 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 17 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 c = 18 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 c = 19 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Column 19 0.7916 c = 20 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 20 0.7916 0.6703 c = 21 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 21 0.7916 0.6703 0.8461 c = 22 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 22 0.7916 0.6703 0.8461 0.8260 c = 23 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 23 0.7916 0.6703 0.8461 0.8260 0.3105 c = 24 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 24 0.7916 0.6703 0.8461 0.8260 0.3105 0.7479 c = 25 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 25 0.7916 0.6703 0.8461 0.8260 0.3105 0.7479 0.1319 c = 26 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 26 0.7916 0.6703 0.8461 0.8260 0.3105 0.7479 0.1319 0.5028 c = 27 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 27 0.7916 0.6703 0.8461 0.8260 0.3105 0.7479 0.1319 0.5028 0.8481 c = 28 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 27 0.7916 0.6703 0.8461 0.8260 0.3105 0.7479 0.1319 0.5028 0.8481 Column 28 0.7528 c = 29 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 27 0.7916 0.6703 0.8461 0.8260 0.3105 0.7479 0.1319 0.5028 0.8481 Columns 28 through 29 0.7528 0.6068 c = 30 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 27 0.7916 0.6703 0.8461 0.8260 0.3105 0.7479 0.1319 0.5028 0.8481 Columns 28 through 30 0.7528 0.6068 0.6240 c = 31 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 27 0.7916 0.6703 0.8461 0.8260 0.3105 0.7479 0.1319 0.5028 0.8481 Columns 28 through 31 0.7528 0.6068 0.6240 0.8793 c = 32 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 27 0.7916 0.6703 0.8461 0.8260 0.3105 0.7479 0.1319 0.5028 0.8481 Columns 28 through 32 0.7528 0.6068 0.6240 0.8793 0.4851 c = 33 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 27 0.7916 0.6703 0.8461 0.8260 0.3105 0.7479 0.1319 0.5028 0.8481 Columns 28 through 33 0.7528 0.6068 0.6240 0.8793 0.4851 0.2222 c = 34 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 27 0.7916 0.6703 0.8461 0.8260 0.3105 0.7479 0.1319 0.5028 0.8481 Columns 28 through 34 0.7528 0.6068 0.6240 0.8793 0.4851 0.2222 0.2214 c = 35 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 27 0.7916 0.6703 0.8461 0.8260 0.3105 0.7479 0.1319 0.5028 0.8481 Columns 28 through 35 0.7528 0.6068 0.6240 0.8793 0.4851 0.2222 0.2214 0.4840 c = 36 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 27 0.7916 0.6703 0.8461 0.8260 0.3105 0.7479 0.1319 0.5028 0.8481 Columns 28 through 36 0.7528 0.6068 0.6240 0.8793 0.4851 0.2222 0.2214 0.4840 0.1413 c = 37 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 27 0.7916 0.6703 0.8461 0.8260 0.3105 0.7479 0.1319 0.5028 0.8481 Columns 28 through 36 0.7528 0.6068 0.6240 0.8793 0.4851 0.2222 0.2214 0.4840 0.1413 Column 37 0.0812 c = 38 y = Columns 1 through 9 0.9714 0.0858 0.3578 0.5968 0.5092 0.5342 0.3060 0.4975 0.2154 Columns 10 through 18 0.4245 0.1573 0.6956 0.9420 0.2193 0.6443 0.2970 0.6019 0.8009 Columns 19 through 27 0.7916 0.6703 0.8461 0.8260 0.3105 0.7479 0.1319 0.5028...

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 = [] c = 1 y = 65 c = 2 y = 65 111 c = 3 y = 65 111 103 c = 4 y = 65 111 103 105 c = 5 y = 65 111 103 105 101 c = 6 y = 65 111 103 105 101 103 c = 7 y = 65 111 103 105 101 103 105 c = 8 y = 65 111 103 105 101 103 105 97 c = 9 y = 65 111 103 105 101 103 105 97 97 c = 10 y = 65 111 103 105 101 103 105 97 97 97 c = 11 y = 65 111 103 105 101 103 105 97 97 97 121 c = 12 y = 65 111 103 105 101 103 105 97 97 97 121 97 c = 13 y = 65 111 103 105 101 103 105 97 97 97 121 97 102 c = 14 y = 65 111 103 105 101 103 105 97 97 97 121 97 102 114 c = 15 y = 65 111 103 105 101 103 105 97 97 97 121 97 102 114 119 c = 16 y = 65 111 103 105 101 103 105 97 97 97 121 97 102 114 119 121 c = 17