Cody

Problem 6. Select every other element of a vector

Solution 2993122

Submitted on 25 Sep 2020 by Yongrong Zuo
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 = 0.8344 0.0169 y = 0.8344 0.0169 0.5739 y = 0.8344 0.0169 0.5739 0.9230 y = 0.8344 0.0169 0.5739 0.9230 0.3925

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

y = 0.3936 0.6207 y = 0.3936 0.6207 0.5655 y = 0.3936 0.6207 0.5655 0.8725 y = 0.3936 0.6207 0.5655 0.8725 0.3168 y = 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 y = 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 y = 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 y = 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 y = 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 y = 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 y = 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 y = 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 y = 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 y = 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 y = 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 y = 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Column 18 0.4590 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 19 0.4590 0.6944 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 20 0.4590 0.6944 0.4132 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 21 0.4590 0.6944 0.4132 0.0119 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 22 0.4590 0.6944 0.4132 0.0119 0.5029 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 23 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 24 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 25 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 26 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 0.7714 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 27 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 0.7714 0.4521 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 28 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 0.7714 0.4521 0.6590 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 29 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 0.7714 0.4521 0.6590 0.6913 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 30 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 0.7714 0.4521 0.6590 0.6913 0.7240 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 31 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 0.7714 0.4521 0.6590 0.6913 0.7240 0.4716 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 32 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 0.7714 0.4521 0.6590 0.6913 0.7240 0.4716 0.1122 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 33 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 0.7714 0.4521 0.6590 0.6913 0.7240 0.4716 0.1122 0.4167 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 34 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 0.7714 0.4521 0.6590 0.6913 0.7240 0.4716 0.1122 0.4167 0.2238 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 34 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 0.7714 0.4521 0.6590 0.6913 0.7240 0.4716 0.1122 0.4167 0.2238 Column 35 0.6089 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 34 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 0.7714 0.4521 0.6590 0.6913 0.7240 0.4716 0.1122 0.4167 0.2238 Columns 35 through 36 0.6089 0.6354 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 34 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 0.7714 0.4521 0.6590 0.6913 0.7240 0.4716 0.1122 0.4167 0.2238 Columns 35 through 37 0.6089 0.6354 0.4013 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 34 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 0.7714 0.4521 0.6590 0.6913 0.7240 0.4716 0.1122 0.4167 0.2238 Columns 35 through 38 0.6089 0.6354 0.4013 0.8044 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 34 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 0.7714 0.4521 0.6590 0.6913 0.7240 0.4716 0.1122 0.4167 0.2238 Columns 35 through 39 0.6089 0.6354 0.4013 0.8044 0.0639 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.8794 0.2586 Columns 18 through 34 0.4590 0.6944 0.4132 0.0119 0.5029 0.1637 0.9411 0.6499 0.7714 0.4521 0.6590 0.6913 0.7240 0.4716 0.1122 0.4167 0.2238 Columns 35 through 40 0.6089 0.6354 0.4013 0.8044 0.0639 0.4716 y = Columns 1 through 17 0.3936 0.6207 0.5655 0.8725 0.3168 0.8010 0.7619 0.0143 0.7997 0.4839 0.9115 0.9537 0.0259 0.2112 0.8850 0.87...

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 = '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!