Cody

Problem 6. Select every other element of a vector

Solution 1820017

Submitted on 20 May 2019 by Praful Tondomker
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.3943 0.2723 0.6245 0.8095 0.2042

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.0948 0.6562 0.1053 0.3210 0.9666 0.8505 0.1154 0.4464 0.6019 0.3945 0.6226 0.5756 0.7307 0.0635 0.4231 0.9352 0.9713 0.4845 Columns 19 through 36 0.5031 0.3484 0.8864 0.5527 0.5934 0.9207 0.4663 0.6493 0.0796 0.8296 0.5182 0.9874 0.0492 0.0899 0.6752 0.8865 0.4937 0.9760 Columns 37 through 50 0.0703 0.3403 0.1459 0.1067 0.3948 0.4602 0.8581 0.2813 0.8950 0.4275 0.1782 0.0561 0.8875 0.2254

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!