Cody

# Problem 6. Select every other element of a vector

Solution 1270363

Submitted on 18 Sep 2017 by omar malik
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.5463 0.2860 0.1175 0.6440 0.2456

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.2452 0.3377 0.9913 0.2787 0.8752 0.2410 0.6782 0.6178 0.5917 0.4617 0.5775 0.3312 0.3446 0.3513 0.9650 0.2323 0.1603 Columns 18 through 34 0.6138 0.0091 0.2828 0.1434 0.9767 0.7308 0.3435 0.4059 0.8846 0.3152 0.4525 0.6528 0.6920 0.1444 0.3889 0.9526 0.1915 Columns 35 through 50 0.3201 0.8270 0.4503 0.3857 0.7468 0.8884 0.6226 0.2771 0.5420 0.5096 0.1462 0.0147 0.7216 0.0542 0.0868 0.7564

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!