Cody

# Problem 6. Select every other element of a vector

Solution 1682559

Submitted on 28 Nov 2018 by Benedikt Gasparic
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 = 1 m = 1 y = 0.4991 n = 3 m = 2 y = 0.4991 0.6332 n = 5 m = 3 y = 0.4991 0.6332 0.3669 n = 7 m = 4 y = 0.4991 0.6332 0.3669 0.2652 n = 9 m = 5 y = 0.4991 0.6332 0.3669 0.2652 0.8093 n = 11 m = 6

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

n = 1 m = 1 y = 0.3570 n = 3 m = 2 y = 0.3570 0.9504 n = 5 m = 3 y = 0.3570 0.9504 0.1651 n = 7 m = 4 y = 0.3570 0.9504 0.1651 0.3804 n = 9 m = 5 y = 0.3570 0.9504 0.1651 0.3804 0.3456 n = 11 m = 6 y = 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 n = 13 m = 7 y = 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 n = 15 m = 8 y = 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 n = 17 m = 9 y = 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 n = 19 m = 10 y = 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 n = 21 m = 11 y = 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 n = 23 m = 12 y = 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 n = 25 m = 13 y = 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 n = 27 m = 14 y = 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 n = 29 m = 15 y = 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 n = 31 m = 16 y = 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 n = 33 m = 17 y = 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 n = 35 m = 18 y = 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 n = 37 m = 19 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Column 19 0.7630 n = 39 m = 20 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 20 0.7630 0.4063 n = 41 m = 21 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 21 0.7630 0.4063 0.9664 n = 43 m = 22 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 22 0.7630 0.4063 0.9664 0.1390 n = 45 m = 23 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 23 0.7630 0.4063 0.9664 0.1390 0.8592 n = 47 m = 24 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 24 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 n = 49 m = 25 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 25 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 0.4306 n = 51 m = 26 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 26 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 0.4306 0.2981 n = 53 m = 27 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 27 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 0.4306 0.2981 0.3222 n = 55 m = 28 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 28 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 0.4306 0.2981 0.3222 0.2333 n = 57 m = 29 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 29 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 0.4306 0.2981 0.3222 0.2333 0.8236 n = 59 m = 30 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 30 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 0.4306 0.2981 0.3222 0.2333 0.8236 0.9358 n = 61 m = 31 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 31 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 0.4306 0.2981 0.3222 0.2333 0.8236 0.9358 0.3939 n = 63 m = 32 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 32 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 0.4306 0.2981 0.3222 0.2333 0.8236 0.9358 0.3939 0.5612 n = 65 m = 33 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 33 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 0.4306 0.2981 0.3222 0.2333 0.8236 0.9358 0.3939 0.5612 0.6269 n = 67 m = 34 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 34 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 0.4306 0.2981 0.3222 0.2333 0.8236 0.9358 0.3939 0.5612 0.6269 0.7756 n = 69 m = 35 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 35 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 0.4306 0.2981 0.3222 0.2333 0.8236 0.9358 0.3939 0.5612 0.6269 0.7756 0.0444 n = 71 m = 36 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 36 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 0.4306 0.2981 0.3222 0.2333 0.8236 0.9358 0.3939 0.5612 0.6269 0.7756 0.0444 0.5604 n = 73 m = 37 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 36 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 0.4306 0.2981 0.3222 0.2333 0.8236 0.9358 0.3939 0.5612 0.6269 0.7756 0.0444 0.5604 Column 37 0.9018 n = 75 m = 38 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 36 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 0.4306 0.2981 0.3222 0.2333 0.8236 0.9358 0.3939 0.5612 0.6269 0.7756 0.0444 0.5604 Columns 37 through 38 0.9018 0.6359 n = 77 m = 39 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.3804 0.3456 0.3422 0.0005 0.9759 0.6790 0.9463 0.2807 0.6716 0.1666 0.2584 0.2407 0.1605 0.1286 0.9568 Columns 19 through 36 0.7630 0.4063 0.9664 0.1390 0.8592 0.8640 0.4306 0.2981 0.3222 0.2333 0.8236 0.9358 0.3939 0.5612 0.6269 0.7756 0.0444 0.5604 Columns 37 through 39 0.9018 0.6359 0.6062 n = 79 m = 40 y = Columns 1 through 18 0.3570 0.9504 0.1651 0.380...

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 = 1 m = 1 y = 'A' n = 3 m = 2 y = 'Ao' n = 5 m = 3 y = 'Aog' n = 7 m = 4 y = 'Aogi' n = 9 m = 5 y = 'Aogie' n = 11 m = 6 y = 'Aogieg' n = 13 m = 7 y = 'Aogiegi' n = 15 m = 8 y = 'Aogiegia' n = 17 m = 9 y = 'Aogiegiaa' n = 19 m = 10 y = 'Aogiegiaaa' n = 21 m = 11 y = 'Aogiegiaaay' n = 23 m = 12 y = 'Aogiegiaaaya' n = 25 m = 13 y = 'Aogiegiaaayaf' n = 27 m = 14 y = 'Aogiegiaaayafr' n = 29 m = 15 y = 'Aogiegiaaayafrw' n = 31 m = 16 y = 'Aogiegiaaayafrwy' n = 33 m = 17