Cody

# Problem 6. Select every other element of a vector

Solution 429215

Submitted on 9 Apr 2014 by Chandrasekhar
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 = Columns 1 through 4 0.503432242302661 0.940165873840059 0.704324989875741 0.765260691598216 Column 5 0.600366108527506

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

ans = Columns 1 through 4 0.991402410187307 0.533170091784520 0.203534975857670 0.782734617130797 Columns 5 through 8 0.172475056690362 0.904472747972678 0.729761408188021 0.182544187104768 Columns 9 through 12 0.152426308559564 0.570073510118257 0.034348919446862 0.176952470020284 Columns 13 through 16 0.575054291839170 0.584637594452392 0.127005989512708 0.501653871239233 Columns 17 through 20 0.882358395573366 0.781154720238704 0.394469987028772 0.759007253963146 Columns 21 through 24 0.810375232224816 0.971922462686877 0.388392988812259 0.858977097009873 Columns 25 through 28 0.505381396988382 0.957773022779702 0.983333653019924 0.643847884048864 Columns 29 through 32 0.461194224020697 0.458445934425705 0.621232156524609 0.948106481197537 Columns 33 through 36 0.065668834100689 0.410242149805371 0.656851495469597 0.984117979947313 Columns 37 through 40 0.129104967353139 0.811637437020486 0.234919640785977 0.380913161623224 Columns 41 through 44 0.986761723260765 0.255626206613261 0.424868792883598 0.230086587007869 Columns 45 through 48 0.128283494772073 0.241483467456347 0.936916082163581 0.954158393714040 Columns 49 through 50 0.477783706045013 0.747175215073168

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!