Cody

# Problem 6. Select every other element of a vector

Solution 2045268

Submitted on 4 Dec 2019 by Derek Withers
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.7168 0.5613 0.8606 0.7059 0.9377

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.0290 0.3347 0.8474 0.6387 0.3381 0.8200 0.2794 0.7162 0.7354 0.3318 0.5142 0.2427 0.2245 0.2871 0.0560 0.8962 0.1068 Columns 18 through 34 0.1166 0.7103 0.6041 0.5373 0.7871 0.5056 0.5701 0.6453 0.0854 0.1373 0.1207 0.3893 0.9300 0.0401 0.3828 0.4937 0.9420 Columns 35 through 50 0.9485 0.7122 0.5117 0.7277 0.6880 0.4785 0.4769 0.7015 0.9827 0.9828 0.1731 0.3154 0.1474 0.8521 0.8555 0.7259

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!