Cody

# Problem 6. Select every other element of a vector

Solution 658914

Submitted on 23 Apr 2015 by vinayak patil
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.2685 0.5812 0.8164 0.5773 0.0904

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

y = Columns 1 through 9 0.9510 0.9432 0.2444 0.4115 0.9873 0.1283 0.1832 0.3618 0.2266 Columns 10 through 18 0.2452 0.2169 0.8925 0.3218 0.9682 0.8016 0.2569 0.2237 0.1444 Columns 19 through 27 0.5928 0.6452 0.4516 0.6840 0.0126 0.4046 0.2011 0.3059 0.4791 Columns 28 through 36 0.6435 0.3004 0.6295 0.7569 0.5294 0.5757 0.0919 0.2532 0.0266 Columns 37 through 45 0.2512 0.0779 0.5507 0.6487 0.0420 0.2989 0.5770 0.4213 0.7802 Columns 46 through 50 0.5215 0.7021 0.5662 0.0926 0.3747

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!