Cody

# Problem 6. Select every other element of a vector

Solution 44633

Submitted on 17 Feb 2012 by Kai
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))

l = 10 y = 0.925425280986515 y = 0.925425280986515 0.186388406230158 y = 0.925425280986515 0.186388406230158 0.050186606585697 y = Columns 1 through 3 0.925425280986515 0.186388406230158 0.050186606585697 Column 4 0.729369435485953 y = Columns 1 through 3 0.925425280986515 0.186388406230158 0.050186606585697 Columns 4 through 5 0.729369435485953 0.338064748642705

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

l = 100 y = 0.450863206704084 y = 0.450863206704084 0.324254811212058 y = 0.450863206704084 0.324254811212058 0.830077173704864 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Column 4 0.333537393949211 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 5 0.333537393949211 0.287838203769745 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Column 7 0.519826549216854 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 8 0.519826549216854 0.055845255034542 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Column 10 0.678767849925557 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 11 0.678767849925557 0.773955089314808 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 12 0.678767849925557 0.773955089314808 0.753581470197562 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 12 0.678767849925557 0.773955089314808 0.753581470197562 Column 13 0.586031153658634 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 12 0.678767849925557 0.773955089314808 0.753581470197562 Columns 13 through 14 0.586031153658634 0.392488258270265 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 12 0.678767849925557 0.773955089314808 0.753581470197562 Columns 13 through 15 0.586031153658634 0.392488258270265 0.247432873807587 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 12 0.678767849925557 0.773955089314808 0.753581470197562 Columns 13 through 15 0.586031153658634 0.392488258270265 0.247432873807587 Column 16 0.019332596723186 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 12 0.678767849925557 0.773955089314808 0.753581470197562 Columns 13 through 15 0.586031153658634 0.392488258270265 0.247432873807587 Columns 16 through 17 0.019332596723186 0.141795751740657 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 12 0.678767849925557 0.773955089314808 0.753581470197562 Columns 13 through 15 0.586031153658634 0.392488258270265 0.247432873807587 Columns 16 through 18 0.019332596723186 0.141795751740657 0.153068350318529 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 12 0.678767849925557 0.773955089314808 0.753581470197562 Columns 13 through 15 0.586031153658634 0.392488258270265 0.247432873807587 Columns 16 through 18 0.019332596723186 0.141795751740657 0.153068350318529 Column 19 0.739199528478463 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 12 0.678767849925557 0.773955089314808 0.753581470197562 Columns 13 through 15 0.586031153658634 0.392488258270265 0.247432873807587 Columns 16 through 18 0.019332596723186 0.141795751740657 0.153068350318529 Columns 19 through 20 0.739199528478463 0.820633088448740 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 12 0.678767849925557 0.773955089314808 0.753581470197562 Columns 13 through 15 0.586031153658634 0.392488258270265 0.247432873807587 Columns 16 through 18 0.019332596723186 0.141795751740657 0.153068350318529 Columns 19 through 21 0.739199528478463 0.820633088448740 0.106941347858146 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 12 0.678767849925557 0.773955089314808 0.753581470197562 Columns 13 through 15 0.586031153658634 0.392488258270265 0.247432873807587 Columns 16 through 18 0.019332596723186 0.141795751740657 0.153068350318529 Columns 19 through 21 0.739199528478463 0.820633088448740 0.106941347858146 Column 22 0.954576107771929 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 12 0.678767849925557 0.773955089314808 0.753581470197562 Columns 13 through 15 0.586031153658634 0.392488258270265 0.247432873807587 Columns 16 through 18 0.019332596723186 0.141795751740657 0.153068350318529 Columns 19 through 21 0.739199528478463 0.820633088448740 0.106941347858146 Columns 22 through 23 0.954576107771929 0.623252783402418 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 12 0.678767849925557 0.773955089314808 0.753581470197562 Columns 13 through 15 0.586031153658634 0.392488258270265 0.247432873807587 Columns 16 through 18 0.019332596723186 0.141795751740657 0.153068350318529 Columns 19 through 21 0.739199528478463 0.820633088448740 0.106941347858146 Columns 22 through 24 0.954576107771929 0.623252783402418 0.277368001720500 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 12 0.678767849925557 0.773955089314808 0.753581470197562 Columns 13 through 15 0.586031153658634 0.392488258270265 0.247432873807587 Columns 16 through 18 0.019332596723186 0.141795751740657 0.153068350318529 Columns 19 through 21 0.739199528478463 0.820633088448740 0.106941347858146 Columns 22 through 24 0.954576107771929 0.623252783402418 0.277368001720500 Column 25 0.350295544428917 y = Columns 1 through 3 0.450863206704084 0.324254811212058 0.830077173704864 Columns 4 through 6 0.333537393949211 0.287838203769745 0.259901265487771 Columns 7 through 9 0.519826549216854 0.055845255034542 0.439927418828113 Columns 10 through 12 0.678767849925557 0.773955089314808 0.753581470197562 Columns 13 through 15 0.586031153658634 0.392488258270265 0.247432873807587 Columns 16 through 18 0.019332596723186 0.141795751740657 0.153068350318529 Columns 19 through 21 0.739199528478463 0.820633088448740 0.106941347858146 Columns 22 through 24 0.954576107771929 0.623252783402418 0.277368001720500 Columns 25 through 26 0.350295544428917 0.006154493311210 y = Column...

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

l = 31 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