Cody

# Problem 6. Select every other element of a vector

Solution 419731

Submitted on 18 Mar 2014 by Wesley Allen
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))

ans = 0.4697 0.2251 0.5134 0.5189 0.9217

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

ans = Columns 1 through 9 0.0064 0.6676 0.6211 0.2566 0.0769 0.7874 0.5939 0.4642 0.0143 Columns 10 through 18 0.7288 0.8090 0.9065 0.1142 0.5770 0.9490 0.9790 0.9112 0.1068 Columns 19 through 27 0.9660 0.0482 0.2787 0.3058 0.9805 0.9534 0.3472 0.7575 0.4528 Columns 28 through 36 0.0220 0.9601 0.8280 0.0284 0.3542 0.3430 0.5872 0.0019 0.3658 Columns 37 through 45 0.4189 0.0949 0.9052 0.2190 0.7002 0.7108 0.6732 0.6856 0.1937 Columns 46 through 50 0.6131 0.9606 0.2772 0.3021 0.0874

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

ans = Aogiegiaaayafrwy

### Community Treasure Hunt

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

Start Hunting!