Cody

# Problem 6. Select every other element of a vector

Solution 56602

Submitted on 5 Mar 2012 by Mathias
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))

y = 0.6985 0.9836 0.6884 0.8072 0.9029

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

y = Columns 1 through 6 0.4297 0.8358 0.6470 0.6719 0.0551 0.2293 Columns 7 through 12 0.4121 0.0543 0.3333 0.0059 0.6229 0.2283 Columns 13 through 18 0.7614 0.9539 0.7539 0.7676 0.3840 0.0006 Columns 19 through 24 0.3132 0.7929 0.7519 0.8976 0.9511 0.8930 Columns 25 through 30 0.1826 0.1411 0.9452 0.3944 0.0248 0.2752 Columns 31 through 36 0.3878 0.2567 0.7872 0.0969 0.1586 0.1930 Columns 37 through 42 0.2428 0.4848 0.4963 0.7562 0.6307 0.9271 Columns 43 through 48 0.8328 0.7283 0.6436 0.3875 0.1689 0.9184 Columns 49 through 50 0.9683 0.2189

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))

y = Aogiegiaaayafrwy

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!