Cody

Problem 6. Select every other element of a vector

Solution 1594052

Submitted on 28 Jul 2018 by MUTHYALA VIKAS CHOWDARY
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.7851 0.8305 0.4131 0.2812 0.4159

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.9713 0.2631 0.9894 0.8706 0.0465 0.3368 0.3571 0.1254 0.4713 0.4966 0.2760 0.4750 0.2623 0.0857 0.9779 0.8198 0.6237 0.8898 Columns 19 through 36 0.0039 0.8800 0.6573 0.0375 0.8336 0.7576 0.4584 0.2064 0.4710 0.5633 0.1767 0.1992 0.1034 0.0132 0.1683 0.7503 0.1855 0.1090 Columns 37 through 50 0.9666 0.6540 0.5028 0.8682 0.0148 0.1824 0.5604 0.7119 0.8418 0.7166 0.1982 0.1561 0.5823 0.0824

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!