Cody

Problem 6. Select every other element of a vector

Solution 1369939

Submitted on 5 Dec 2017 by Rohan Lallbachan
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.7264 0.0942 0.8926 0.6857 0.1529

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.5383 0.4276 0.5056 0.8702 0.9898 0.9792 0.3276 0.9073 0.4795 0.5485 0.7114 0.6423 0.5353 0.2876 0.6797 0.2052 0.3124 0.3956 Columns 19 through 36 0.6960 0.4765 0.7631 0.0711 0.0029 0.2051 0.2093 0.5979 0.5498 0.8935 0.9370 0.0938 0.1851 0.1156 0.1895 0.8156 0.1902 0.6880 Columns 37 through 50 0.6842 0.8150 0.3512 0.9518 0.6324 0.2694 0.3001 0.8335 0.5733 0.2046 0.3697 0.3685 0.6135 0.1434

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!