Cody

Problem 6. Select every other element of a vector

Solution 1338205

Submitted on 13 Nov 2017 by Thomas Pingnam
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.9993 0.6653 0.0655 0.0010 0.0710

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

y = Columns 1 through 17 0.2288 0.8056 0.2192 0.4999 0.8794 0.2843 0.1150 0.9347 0.8074 0.7760 0.9709 0.1213 0.7935 0.1713 0.4536 0.8708 0.7889 Columns 18 through 34 0.8720 0.6504 0.7664 0.6527 0.9447 0.2402 0.5859 0.7123 0.3065 0.4505 0.2046 0.9160 0.8616 0.0065 0.8558 0.5722 0.9353 Columns 35 through 50 0.9357 0.4273 0.6444 0.6633 0.4701 0.4763 0.1540 0.8419 0.9297 0.4107 0.4869 0.6260 0.5091 0.4881 0.2382 0.7672

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'

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!