Cody

# Problem 6. Select every other element of a vector

Solution 2012256

Submitted on 10 Nov 2019 by Paulo Cerqueira
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.9432 0.0122 0.9842 0.0504 0.7996

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.5881 0.7687 0.2031 0.5844 0.3066 0.0154 0.6962 0.4198 0.3146 0.2957 0.0136 0.7916 0.0771 0.5536 0.3277 0.6571 0.5075 0.2920 Columns 19 through 36 0.5796 0.0577 0.9484 0.3072 0.7311 0.4519 0.9727 0.3327 0.6458 0.7110 0.2821 0.9686 0.4613 0.7070 0.5532 0.5600 0.0609 0.5190 Columns 37 through 50 0.8376 0.9131 0.0605 0.9375 0.0182 0.0086 0.8246 0.9068 0.0089 0.4880 0.4096 0.9946 0.0846 0.6295

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!