Cody

Problem 6. Select every other element of a vector

Solution 519137

Submitted on 1 Nov 2014 by Shrabya
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.0366 0.7084 0.2377 0.3314 0.4834

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

y = Columns 1 through 9 0.9319 0.4694 0.9402 0.9563 0.5079 0.0378 0.4891 0.4037 0.7057 Columns 10 through 18 0.2841 0.6279 0.6402 0.7821 0.2230 0.9445 0.0789 0.7636 0.8088 Columns 19 through 27 0.2940 0.8726 0.5328 0.5691 0.1674 0.2205 0.4184 0.1597 0.4366 Columns 28 through 36 0.0157 0.7680 0.4286 0.9060 0.9586 0.4559 0.7852 0.5181 0.8516 Columns 37 through 45 0.4341 0.6919 0.9521 0.5510 0.9667 0.9617 0.2398 0.5116 0.0314 Columns 46 through 50 0.0937 0.8712 0.0816 0.5070 0.8967

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!