Cody

# Problem 6. Select every other element of a vector

Solution 1093490

Submitted on 29 Dec 2016 by edwin chua
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.1017 0.0407 0.0534 0.7486 0.0840

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

ans = Columns 1 through 17 0.7131 0.9639 0.6698 0.6687 0.7716 0.6193 0.8602 0.8105 0.9086 0.3338 0.0008 0.9349 0.2560 0.8650 0.0566 0.4955 0.4370 Columns 18 through 34 0.6026 0.9671 0.8367 0.1932 0.9680 0.4014 0.6733 0.7397 0.2703 0.5043 0.7107 0.8161 0.3910 0.7600 0.5720 0.6667 0.1787 Columns 35 through 50 0.2582 0.8389 0.5622 0.7370 0.3713 0.9568 0.3670 0.4288 0.1328 0.1479 0.8478 0.4509 0.5307 0.7634 0.9416 0.1464

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!