Cody

# Problem 6. Select every other element of a vector

Solution 565533

Submitted on 26 Jan 2015 by SmileyPhysics
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.7267 y = 0.7267 0.4251 y = 0.7267 0.4251 0.2417 y = 0.7267 0.4251 0.2417 0.2937 y = 0.7267 0.4251 0.2417 0.2937 0.4854

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

y = [] y = 0.4195 y = 0.4195 0.1340 y = 0.4195 0.1340 0.6851 y = 0.4195 0.1340 0.6851 0.4398 y = 0.4195 0.1340 0.6851 0.4398 0.6250 y = 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 y = 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 y = 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 y = 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Column 10 0.9694 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 11 0.9694 0.5571 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 12 0.9694 0.5571 0.5336 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 13 0.9694 0.5571 0.5336 0.1240 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 14 0.9694 0.5571 0.5336 0.1240 0.0963 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 15 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 16 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 17 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Column 19 0.1543 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 20 0.1543 0.8082 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 21 0.1543 0.8082 0.3737 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 22 0.1543 0.8082 0.3737 0.6893 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 23 0.1543 0.8082 0.3737 0.6893 0.3643 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 24 0.1543 0.8082 0.3737 0.6893 0.3643 0.1374 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 25 0.1543 0.8082 0.3737 0.6893 0.3643 0.1374 0.4576 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 26 0.1543 0.8082 0.3737 0.6893 0.3643 0.1374 0.4576 0.4443 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 27 0.1543 0.8082 0.3737 0.6893 0.3643 0.1374 0.4576 0.4443 0.1514 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 27 0.1543 0.8082 0.3737 0.6893 0.3643 0.1374 0.4576 0.4443 0.1514 Column 28 0.4192 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 27 0.1543 0.8082 0.3737 0.6893 0.3643 0.1374 0.4576 0.4443 0.1514 Columns 28 through 29 0.4192 0.7392 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 27 0.1543 0.8082 0.3737 0.6893 0.3643 0.1374 0.4576 0.4443 0.1514 Columns 28 through 30 0.4192 0.7392 0.2192 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 27 0.1543 0.8082 0.3737 0.6893 0.3643 0.1374 0.4576 0.4443 0.1514 Columns 28 through 31 0.4192 0.7392 0.2192 0.6105 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 27 0.1543 0.8082 0.3737 0.6893 0.3643 0.1374 0.4576 0.4443 0.1514 Columns 28 through 32 0.4192 0.7392 0.2192 0.6105 0.6058 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 27 0.1543 0.8082 0.3737 0.6893 0.3643 0.1374 0.4576 0.4443 0.1514 Columns 28 through 33 0.4192 0.7392 0.2192 0.6105 0.6058 0.9495 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 27 0.1543 0.8082 0.3737 0.6893 0.3643 0.1374 0.4576 0.4443 0.1514 Columns 28 through 34 0.4192 0.7392 0.2192 0.6105 0.6058 0.9495 0.3540 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 27 0.1543 0.8082 0.3737 0.6893 0.3643 0.1374 0.4576 0.4443 0.1514 Columns 28 through 35 0.4192 0.7392 0.2192 0.6105 0.6058 0.9495 0.3540 0.6731 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 27 0.1543 0.8082 0.3737 0.6893 0.3643 0.1374 0.4576 0.4443 0.1514 Columns 28 through 36 0.4192 0.7392 0.2192 0.6105 0.6058 0.9495 0.3540 0.6731 0.8239 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 27 0.1543 0.8082 0.3737 0.6893 0.3643 0.1374 0.4576 0.4443 0.1514 Columns 28 through 36 0.4192 0.7392 0.2192 0.6105 0.6058 0.9495 0.3540 0.6731 0.8239 Column 37 0.6470 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 through 27 0.1543 0.8082 0.3737 0.6893 0.3643 0.1374 0.4576 0.4443 0.1514 Columns 28 through 36 0.4192 0.7392 0.2192 0.6105 0.6058 0.9495 0.3540 0.6731 0.8239 Columns 37 through 38 0.6470 0.3087 y = Columns 1 through 9 0.4195 0.1340 0.6851 0.4398 0.6250 0.5887 0.9810 0.7513 0.6880 Columns 10 through 18 0.9694 0.5571 0.5336 0.1240 0.0963 0.5383 0.1972 0.2115 0.1844 Columns 19 th...

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!