Cody

Problem 6. Select every other element of a vector

Solution 1467258

Submitted on 20 Mar 2018 by Zhengyi
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.3927 0.7958 0.9603 0.8955 0.0610

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.7078 0.0835 0.7085 0.3982 0.2247 0.0259 0.4561 0.8369 0.5843 0.6944 0.0343 0.7839 0.7864 0.4532 0.8849 0.0633 0.6108 0.9143 Columns 19 through 36 0.6572 0.1733 0.2280 0.7701 0.5230 0.2984 0.4793 0.8137 0.3040 0.7747 0.0851 0.1918 0.6648 0.9322 0.1206 0.9186 0.7061 0.3648 Columns 37 through 50 0.9203 0.1649 0.5763 0.6403 0.7566 0.6754 0.4148 0.9442 0.3760 0.3478 0.7536 0.0895 0.1089 0.3503

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'

Suggested Problems

More from this Author95

Community Treasure Hunt

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

Start Hunting!