Cody

Problem 6. Select every other element of a vector

Solution 592623

Submitted on 6 Mar 2015 by Dougal
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))

ans = 0.9742 0.9665 0.7818 0.9939 0.5510

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

ans = Columns 1 through 9 0.8950 0.6878 0.5410 0.8962 0.5871 0.2899 0.5516 0.2763 0.9748 Columns 10 through 18 0.1225 0.9550 0.7561 0.5934 0.8140 0.7150 0.3510 0.2005 0.5012 Columns 19 through 27 0.1962 0.5539 0.3685 0.4393 0.5573 0.7619 0.2454 0.5493 0.0137 Columns 28 through 36 0.4302 0.6505 0.3656 0.1486 0.4321 0.2727 0.8625 0.7441 0.5235 Columns 37 through 45 0.9750 0.3135 0.4768 0.4445 0.0537 0.6063 0.0317 0.5748 0.6433 Columns 46 through 50 0.4235 0.6734 0.3859 0.3743 0.6898

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))

ans = 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!