Cody

Problem 6. Select every other element of a vector

Solution 2177011

Submitted on 26 Mar 2020 by Hans-Martin Schlesier
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.5297 0.8867 0.2927 0.7008 0.3669

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.4494 0.5338 0.9663 0.2377 0.9668 0.4683 0.8147 0.2164 0.2333 0.4019 0.5132 0.1570 0.3967 0.9087 0.3946 0.9108 0.2489 Columns 18 through 34 0.9629 0.0397 0.6603 0.1081 0.7671 0.3479 0.4702 0.9094 0.7872 0.5398 0.4173 0.7457 0.6149 0.9735 0.0830 0.5743 0.8744 Columns 35 through 50 0.2031 0.2848 0.6214 0.1055 0.3350 0.7494 0.6869 0.2795 0.8401 0.1864 0.0907 0.6395 0.3678 0.1307 0.3486 0.6798

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!