Cody

Problem 6. Select every other element of a vector

Solution 2255473

Submitted on 5 May 2020 by Uchechukwu Obimma
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.0313 0.5529 0.1869 0.2307 0.3178

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

y = Columns 1 through 18 0.7678 0.5781 0.7036 0.8404 0.0213 0.8046 0.3344 0.3728 0.6397 0.4653 0.2295 0.5784 0.5461 0.6154 0.4571 0.4431 0.9580 0.3239 Columns 19 through 36 0.4310 0.8884 0.1585 0.5738 0.3909 0.0036 0.2892 0.9905 0.2863 0.7740 0.7494 0.3483 0.5795 0.8332 0.2307 0.1028 0.3791 0.7559 Columns 37 through 50 0.8639 0.5490 0.6167 0.4635 0.2791 0.5671 0.3784 0.6739 0.0706 0.4246 0.1453 0.7150 0.0403 0.6661

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!