Cody

# Problem 6. Select every other element of a vector

Solution 2817706

Submitted on 11 Aug 2020 by Yin-Lung Wong
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 = [] y = 0.9571 y = 0.9571 0.8637 y = 0.9571 0.8637 0.8044 y = 0.9571 0.8637 0.8044 0.8891 y = 0.9571 0.8637 0.8044 0.8891 0.0583

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

y = [] y = 0.6959 y = 0.6959 0.1505 y = 0.6959 0.1505 0.4123 y = 0.6959 0.1505 0.4123 0.7538 y = 0.6959 0.1505 0.4123 0.7538 0.8130 y = 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 y = 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 y = 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 y = 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 y = 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 y = 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 y = 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 y = 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 y = 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 y = 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 y = 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 y = 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 y = 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Column 19 0.4482 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 20 0.4482 0.7550 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 21 0.4482 0.7550 0.7102 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 22 0.4482 0.7550 0.7102 0.3187 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 23 0.4482 0.7550 0.7102 0.3187 0.4539 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 24 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 25 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 26 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 0.5290 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 27 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 0.5290 0.4394 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 28 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 0.5290 0.4394 0.1717 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 29 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 0.5290 0.4394 0.1717 0.5757 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 30 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 0.5290 0.4394 0.1717 0.5757 0.5867 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 31 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 0.5290 0.4394 0.1717 0.5757 0.5867 0.8005 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 32 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 0.5290 0.4394 0.1717 0.5757 0.5867 0.8005 0.3261 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 33 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 0.5290 0.4394 0.1717 0.5757 0.5867 0.8005 0.3261 0.4089 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 34 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 0.5290 0.4394 0.1717 0.5757 0.5867 0.8005 0.3261 0.4089 0.4222 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 35 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 0.5290 0.4394 0.1717 0.5757 0.5867 0.8005 0.3261 0.4089 0.4222 0.4746 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 36 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 0.5290 0.4394 0.1717 0.5757 0.5867 0.8005 0.3261 0.4089 0.4222 0.4746 0.8443 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 36 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 0.5290 0.4394 0.1717 0.5757 0.5867 0.8005 0.3261 0.4089 0.4222 0.4746 0.8443 Column 37 0.7088 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 36 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 0.5290 0.4394 0.1717 0.5757 0.5867 0.8005 0.3261 0.4089 0.4222 0.4746 0.8443 Columns 37 through 38 0.7088 0.2035 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 36 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 0.5290 0.4394 0.1717 0.5757 0.5867 0.8005 0.3261 0.4089 0.4222 0.4746 0.8443 Columns 37 through 39 0.7088 0.2035 0.7227 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 36 0.4482 0.7550 0.7102 0.3187 0.4539 0.2667 0.6720 0.5290 0.4394 0.1717 0.5757 0.5867 0.8005 0.3261 0.4089 0.4222 0.4746 0.8443 Columns 37 through 40 0.7088 0.2035 0.7227 0.3401 y = Columns 1 through 18 0.6959 0.1505 0.4123 0.7538 0.8130 0.6819 0.4534 0.6806 0.8451 0.3434 0.7166 0.9087 0.1319 0.1192 0.8969 0.8875 0.5515 0.9279 Columns 19 through 36 0.4482 0.7550 ...

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 = [] 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'

### Community Treasure Hunt

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

Start Hunting!