Cody

# Problem 6. Select every other element of a vector

Solution 788693

Submitted on 4 Dec 2015 by Pedro Pascual González
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))

n = 10 y = 0.2471 y = 0.2471 0.2792 y = 0.2471 0.2792 0.3963 y = 0.2471 0.2792 0.3963 0.3195 y = 0.2471 0.2792 0.3963 0.3195 0.9185

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

n = 100 y = 0.7181 y = 0.7181 0.5871 y = 0.7181 0.5871 0.4329 y = 0.7181 0.5871 0.4329 0.8454 y = 0.7181 0.5871 0.4329 0.8454 0.7566 y = 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 y = 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 y = 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 y = 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Column 10 0.1124 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 11 0.1124 0.7598 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 12 0.1124 0.7598 0.8915 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 13 0.1124 0.7598 0.8915 0.0164 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 14 0.1124 0.7598 0.8915 0.0164 0.3385 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 15 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 16 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 17 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Column 19 0.4755 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 20 0.4755 0.6930 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 21 0.4755 0.6930 0.0959 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 22 0.4755 0.6930 0.0959 0.0650 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 23 0.4755 0.6930 0.0959 0.0650 0.0127 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 24 0.4755 0.6930 0.0959 0.0650 0.0127 0.7198 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 25 0.4755 0.6930 0.0959 0.0650 0.0127 0.7198 0.7513 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 26 0.4755 0.6930 0.0959 0.0650 0.0127 0.7198 0.7513 0.2406 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 27 0.4755 0.6930 0.0959 0.0650 0.0127 0.7198 0.7513 0.2406 0.1188 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 27 0.4755 0.6930 0.0959 0.0650 0.0127 0.7198 0.7513 0.2406 0.1188 Column 28 0.7309 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 27 0.4755 0.6930 0.0959 0.0650 0.0127 0.7198 0.7513 0.2406 0.1188 Columns 28 through 29 0.7309 0.7171 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 27 0.4755 0.6930 0.0959 0.0650 0.0127 0.7198 0.7513 0.2406 0.1188 Columns 28 through 30 0.7309 0.7171 0.0916 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 27 0.4755 0.6930 0.0959 0.0650 0.0127 0.7198 0.7513 0.2406 0.1188 Columns 28 through 31 0.7309 0.7171 0.0916 0.2834 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 27 0.4755 0.6930 0.0959 0.0650 0.0127 0.7198 0.7513 0.2406 0.1188 Columns 28 through 32 0.7309 0.7171 0.0916 0.2834 0.2919 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 27 0.4755 0.6930 0.0959 0.0650 0.0127 0.7198 0.7513 0.2406 0.1188 Columns 28 through 33 0.7309 0.7171 0.0916 0.2834 0.2919 0.6190 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 27 0.4755 0.6930 0.0959 0.0650 0.0127 0.7198 0.7513 0.2406 0.1188 Columns 28 through 34 0.7309 0.7171 0.0916 0.2834 0.2919 0.6190 0.4431 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 27 0.4755 0.6930 0.0959 0.0650 0.0127 0.7198 0.7513 0.2406 0.1188 Columns 28 through 35 0.7309 0.7171 0.0916 0.2834 0.2919 0.6190 0.4431 0.8373 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 27 0.4755 0.6930 0.0959 0.0650 0.0127 0.7198 0.7513 0.2406 0.1188 Columns 28 through 36 0.7309 0.7171 0.0916 0.2834 0.2919 0.6190 0.4431 0.8373 0.8740 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 27 0.4755 0.6930 0.0959 0.0650 0.0127 0.7198 0.7513 0.2406 0.1188 Columns 28 through 36 0.7309 0.7171 0.0916 0.2834 0.2919 0.6190 0.4431 0.8373 0.8740 Column 37 0.4315 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 through 27 0.4755 0.6930 0.0959 0.0650 0.0127 0.7198 0.7513 0.2406 0.1188 Columns 28 through 36 0.7309 0.7171 0.0916 0.2834 0.2919 0.6190 0.4431 0.8373 0.8740 Columns 37 through 38 0.4315 0.1474 y = Columns 1 through 9 0.7181 0.5871 0.4329 0.8454 0.7566 0.6597 0.4279 0.0478 0.4253 Columns 10 through 18 0.1124 0.7598 0.8915 0.0164 0.3385 0.3687 0.6540 0.9444 0.4059 Columns 19 thr...

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

n = 31 y = A y = Ao y = Aog y = Aogi y = Aogie y = Aogieg y = Aogiegi y = Aogiegia y = Aogiegiaa y = Aogiegiaaa y = Aogiegiaaay y = Aogiegiaaaya y = Aogiegiaaayaf y = Aogiegiaaayafr y = Aogiegiaaayafrw y = Aogiegiaaayafrwy