Cody

# Problem 6. Select every other element of a vector

Solution 1544768

Submitted on 31 May 2018 by Danuanping
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.9801 0.8942 0.9090 0.7264 0.5276

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

ans = Columns 1 through 18 0.0690 0.0528 0.2401 0.0339 0.9511 0.2357 0.3164 0.7449 0.0895 0.3736 0.0594 0.3389 0.0483 0.7791 0.2692 0.8188 0.1544 0.7929 Columns 19 through 36 0.3326 0.3716 0.0104 0.5396 0.2692 0.7858 0.9227 0.6100 0.1611 0.2476 0.2932 0.6287 0.0914 0.5067 0.2070 0.1588 0.7809 0.1378 Columns 37 through 50 0.5262 0.6786 0.1533 0.7458 0.7559 0.9564 0.9678 0.9241 0.6192 0.4128 0.5009 0.7829 0.7266 0.7277

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!