Cody

# Problem 6. Select every other element of a vector

Solution 1091116

Submitted on 27 Dec 2016 by Kunwar Abdul Rahman
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.9555 0.5237 0.3228 0.7221 0.7566

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.5666 0.1889 0.1850 0.7315 0.2351 0.0284 0.5350 0.4527 0.7566 Columns 10 through 18 0.6229 0.4742 0.6510 0.8223 0.2733 0.6228 0.8062 0.0043 0.3006 Columns 19 through 27 0.2644 0.0419 0.3911 0.2263 0.1355 0.7304 0.5914 0.6899 0.2546 Columns 28 through 36 0.3755 0.2924 0.6985 0.1324 0.5476 0.0266 0.6539 0.2798 0.3719 Columns 37 through 45 0.8837 0.1355 0.1580 0.9349 0.9450 0.7279 0.1130 0.7168 0.1524 Columns 46 through 50 0.2381 0.7976 0.7350 0.8651 0.5648

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!