Cody

Problem 6. Select every other element of a vector

Solution 1313770

Submitted on 25 Oct 2017 by Eric G.
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.9209 0.4451 0.3722 0.0603 0.5099

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.4217 0.7316 0.4489 0.5462 0.5670 0.9540 0.8766 0.4028 0.7161 0.1734 0.6561 0.8276 0.2058 0.1928 0.9878 0.5328 0.7809 0.0607 Columns 19 through 36 0.3149 0.8275 0.9459 0.7403 0.2642 0.8735 0.5211 0.0865 0.7638 0.3192 0.7867 0.8662 0.0469 0.7786 0.9700 0.2217 0.4105 0.3027 Columns 37 through 50 0.5953 0.1944 0.8257 0.7533 0.9552 0.0465 0.8632 0.5297 0.3281 0.5649 0.5609 0.5049 0.9577 0.0109

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!