Cody

# Problem 6. Select every other element of a vector

Solution 3419418

Submitted on 27 Oct 2020 by Elena Mendez-Romero
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))

r = 10 p = 1 y = 0.4092 p = 2 y = 0.4092 0.4451 p = 3 y = 0.4092 0.4451 0.8784 p = 4 y = 0.4092 0.4451 0.8784 0.3316 p = 5 y = 0.4092 0.4451 0.8784 0.3316 0.7005 p = 6

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

r = 100 p = 1 y = 0.1472 p = 2 y = 0.1472 0.1866 p = 3 y = 0.1472 0.1866 0.8166 p = 4 y = 0.1472 0.1866 0.8166 0.3126 p = 5 y = 0.1472 0.1866 0.8166 0.3126 0.7193 p = 6 y = 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 p = 7 y = 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 p = 8 y = 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 p = 9 y = 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 p = 10 y = 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 p = 11 y = 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 p = 12 y = 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 p = 13 y = 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 p = 14 y = 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 p = 15 y = 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 p = 16 y = 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 p = 17 y = 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 p = 18 y = 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 p = 19 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Column 19 0.2601 p = 20 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 20 0.2601 0.9262 p = 21 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 21 0.2601 0.9262 0.4439 p = 22 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 22 0.2601 0.9262 0.4439 0.2109 p = 23 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 23 0.2601 0.9262 0.4439 0.2109 0.2108 p = 24 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 24 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 p = 25 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 25 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 0.0090 p = 26 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 26 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 0.0090 0.3392 p = 27 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 27 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 0.0090 0.3392 0.8267 p = 28 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 28 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 0.0090 0.3392 0.8267 0.5409 p = 29 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 29 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 0.0090 0.3392 0.8267 0.5409 0.9915 p = 30 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 30 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 0.0090 0.3392 0.8267 0.5409 0.9915 0.5415 p = 31 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 31 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 0.0090 0.3392 0.8267 0.5409 0.9915 0.5415 0.2475 p = 32 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 32 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 0.0090 0.3392 0.8267 0.5409 0.9915 0.5415 0.2475 0.6049 p = 33 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 33 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 0.0090 0.3392 0.8267 0.5409 0.9915 0.5415 0.2475 0.6049 0.7653 p = 34 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 34 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 0.0090 0.3392 0.8267 0.5409 0.9915 0.5415 0.2475 0.6049 0.7653 0.0107 p = 35 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 35 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 0.0090 0.3392 0.8267 0.5409 0.9915 0.5415 0.2475 0.6049 0.7653 0.0107 0.8298 p = 36 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 36 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 0.0090 0.3392 0.8267 0.5409 0.9915 0.5415 0.2475 0.6049 0.7653 0.0107 0.8298 0.8402 p = 37 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 36 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 0.0090 0.3392 0.8267 0.5409 0.9915 0.5415 0.2475 0.6049 0.7653 0.0107 0.8298 0.8402 Column 37 0.1684 p = 38 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 36 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 0.0090 0.3392 0.8267 0.5409 0.9915 0.5415 0.2475 0.6049 0.7653 0.0107 0.8298 0.8402 Columns 37 through 38 0.1684 0.7338 p = 39 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8235 0.6762 0.1189 Columns 19 through 36 0.2601 0.9262 0.4439 0.2109 0.2108 0.5516 0.0090 0.3392 0.8267 0.5409 0.9915 0.5415 0.2475 0.6049 0.7653 0.0107 0.8298 0.8402 Columns 37 through 39 0.1684 0.7338 0.3664 p = 40 y = Columns 1 through 18 0.1472 0.1866 0.8166 0.3126 0.7193 0.9037 0.3652 0.6102 0.2428 0.1723 0.5830 0.2231 0.6448 0.2049 0.5569 0.8...

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

r = 31 p = 1 y = 'A' p = 2 y = 'Ao' p = 3 y = 'Aog' p = 4 y = 'Aogi' p = 5 y = 'Aogie' p = 6 y = 'Aogieg' p = 7 y = 'Aogiegi' p = 8 y = 'Aogiegia' p = 9 y = 'Aogiegiaa' p = 10 y = 'Aogiegiaaa' p = 11 y = 'Aogiegiaaay' p = 12 y = 'Aogiegiaaaya' p = 13 y = 'Aogiegiaaayaf' p = 14 y = 'Aogiegiaaayafr' p = 15 y = 'Aogiegiaaayafrw' p = 16 y = 'Aogiegiaaayafrwy' p = 17

### Community Treasure Hunt

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

Start Hunting!