Cody

Problem 6. Select every other element of a vector

Solution 2334963

Submitted on 22 May 2020 by Gregory Karathymios
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.3466 0.5976 0.7706 0.6109 0.1790

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.0215 0.7936 0.3191 0.5497 0.1990 0.7915 0.8432 0.2154 0.4523 0.3711 0.3737 0.8512 0.7480 0.2748 0.5370 0.1530 0.0538 Columns 18 through 34 0.0368 0.1780 0.0589 0.4906 0.1831 0.5752 0.5378 0.4177 0.8379 0.2413 0.0339 0.5744 0.2414 0.0125 0.4511 0.2086 0.7534 Columns 35 through 50 0.0248 0.6265 0.5457 0.1099 0.0171 0.7683 0.5357 0.9327 0.7683 0.3649 0.3433 0.1053 0.8226 0.2917 0.1048 0.0360

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!