Cody

Problem 6. Select every other element of a vector

Solution 156881

Submitted on 2 Nov 2012 by Claudio Gelmi
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.9058 0.9134 0.0975 0.5469 0.9649

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

y = Columns 1 through 6 0.9706 0.4854 0.1419 0.9157 0.9595 0.0357 Columns 7 through 12 0.9340 0.7577 0.3922 0.1712 0.0318 0.0462 Columns 13 through 18 0.8235 0.3171 0.0344 0.3816 0.7952 0.4898 Columns 19 through 24 0.6463 0.7547 0.6797 0.1626 0.4984 0.3404 Columns 25 through 30 0.2238 0.2551 0.6991 0.9593 0.1386 0.2575 Columns 31 through 36 0.2543 0.2435 0.3500 0.2511 0.4733 0.8308 Columns 37 through 42 0.5497 0.2858 0.7537 0.5678 0.0540 0.7792 Columns 43 through 48 0.1299 0.4694 0.3371 0.7943 0.5285 0.6020 Columns 49 through 50 0.6541 0.7482

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!