Cody

# Problem 6. Select every other element of a vector

Solution 167744

Submitted on 25 Nov 2012 by Mehmet OZC
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.006154493311210 y = 0.006154493311210 0.338063107415899 y = 0.006154493311210 0.338063107415899 0.648100699635131 y = 0.006154493311210 0.338063107415899 0.648100699635131 0.893073781095652 y = 0.006154493311210 0.338063107415899 0.648100699635131 0.893073781095652 0.072883891250741

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

y = 0.981568230272936 y = 0.981568230272936 0.686158658288716 y = 0.981568230272936 0.686158658288716 0.141816370950941 y = 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 y = 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Column 6 0.846597902117332 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 7 0.846597902117332 0.900278066682986 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 8 0.846597902117332 0.900278066682986 0.836510771646748 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 9 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Column 11 0.908637059175440 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 12 0.908637059175440 0.696357727955666 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 13 0.908637059175440 0.696357727955666 0.824149356327936 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 14 0.908637059175440 0.696357727955666 0.824149356327936 0.099642302961614 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 15 0.908637059175440 0.696357727955666 0.824149356327936 0.099642302961614 0.103814782651106 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 15 0.908637059175440 0.696357727955666 0.824149356327936 0.099642302961614 0.103814782651106 Column 16 0.902925119282939 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 15 0.908637059175440 0.696357727955666 0.824149356327936 0.099642302961614 0.103814782651106 Columns 16 through 17 0.902925119282939 0.281589166159224 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 15 0.908637059175440 0.696357727955666 0.824149356327936 0.099642302961614 0.103814782651106 Columns 16 through 18 0.902925119282939 0.281589166159224 0.495871665666786 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 15 0.908637059175440 0.696357727955666 0.824149356327936 0.099642302961614 0.103814782651106 Columns 16 through 19 0.902925119282939 0.281589166159224 0.495871665666786 0.737940751495519 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 15 0.908637059175440 0.696357727955666 0.824149356327936 0.099642302961614 0.103814782651106 Columns 16 through 20 0.902925119282939 0.281589166159224 0.495871665666786 0.737940751495519 0.600407500351151 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 15 0.908637059175440 0.696357727955666 0.824149356327936 0.099642302961614 0.103814782651106 Columns 16 through 20 0.902925119282939 0.281589166159224 0.495871665666786 0.737940751495519 0.600407500351151 Column 21 0.111533124684943 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 15 0.908637059175440 0.696357727955666 0.824149356327936 0.099642302961614 0.103814782651106 Columns 16 through 20 0.902925119282939 0.281589166159224 0.495871665666786 0.737940751495519 0.600407500351151 Columns 21 through 22 0.111533124684943 0.870371220311720 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 15 0.908637059175440 0.696357727955666 0.824149356327936 0.099642302961614 0.103814782651106 Columns 16 through 20 0.902925119282939 0.281589166159224 0.495871665666786 0.737940751495519 0.600407500351151 Columns 21 through 23 0.111533124684943 0.870371220311720 0.242970250921629 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 15 0.908637059175440 0.696357727955666 0.824149356327936 0.099642302961614 0.103814782651106 Columns 16 through 20 0.902925119282939 0.281589166159224 0.495871665666786 0.737940751495519 0.600407500351151 Columns 21 through 24 0.111533124684943 0.870371220311720 0.242970250921629 0.545439787975426 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 15 0.908637059175440 0.696357727955666 0.824149356327936 0.099642302961614 0.103814782651106 Columns 16 through 20 0.902925119282939 0.281589166159224 0.495871665666786 0.737940751495519 0.600407500351151 Columns 21 through 25 0.111533124684943 0.870371220311720 0.242970250921629 0.545439787975426 0.410448399698545 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 15 0.908637059175440 0.696357727955666 0.824149356327936 0.099642302961614 0.103814782651106 Columns 16 through 20 0.902925119282939 0.281589166159224 0.495871665666786 0.737940751495519 0.600407500351151 Columns 21 through 25 0.111533124684943 0.870371220311720 0.242970250921629 0.545439787975426 0.410448399698545 Column 26 0.488973556424727 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 15 0.908637059175440 0.696357727955666 0.824149356327936 0.099642302961614 0.103814782651106 Columns 16 through 20 0.902925119282939 0.281589166159224 0.495871665666786 0.737940751495519 0.600407500351151 Columns 21 through 25 0.111533124684943 0.870371220311720 0.242970250921629 0.545439787975426 0.410448399698545 Columns 26 through 27 0.488973556424727 0.377847951671179 y = Columns 1 through 5 0.981568230272936 0.686158658288716 0.141816370950941 0.019761961290184 0.238306087550869 Columns 6 through 10 0.846597902117332 0.900278066682986 0.836510771646748 0.742745575901670 0.289183690602033 Columns 11 through 15 0.908637059175440 0.696357727955666 0.824149356327936 0.099642302961614 0.103814782651106 Columns 16 through 20 0....

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