Cody

# Problem 6. Select every other element of a vector

Solution 344656

Submitted on 2 Nov 2013 by Stefan Kopecz
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.6473 0.7210 0.9937 0.1058 0.0636

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

y = Columns 1 through 10 0.4484 0.7635 0.7720 0.9727 0.1389 0.0938 0.5303 0.4849 0.6714 0.5201 Columns 11 through 20 0.1500 0.2621 0.7549 0.4424 0.3592 0.3947 0.7040 0.0196 0.4243 0.1971 Columns 21 through 30 0.4299 0.3912 0.3968 0.7551 0.2160 0.9493 0.6713 0.8335 0.1673 0.9899 Columns 31 through 40 0.8843 0.1548 0.4070 0.8256 0.3185 0.0900 0.1363 0.4952 0.4950 0.0550 Columns 41 through 50 0.5606 0.6967 0.8154 0.9889 0.8654 0.9900 0.4795 0.2278 0.9009 0.8452

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!