Cody

Problem 6. Select every other element of a vector

Solution 362658

Submitted on 2 Dec 2013 by Akshay Rawal
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))

0.8692 0.6798 0.8327 0.4015 0.1873

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

Columns 1 through 10 0.1516 0.1802 0.3864 0.9474 0.9454 0.4983 0.1164 0.3463 0.7877 0.0191 Columns 11 through 20 0.7004 0.3078 0.4668 0.2913 0.6527 0.1345 0.1052 0.0116 0.6405 0.8681 Columns 21 through 30 0.5197 0.3482 0.2384 0.5710 0.1779 0.2760 0.8345 0.5160 0.9804 0.3491 Columns 31 through 40 0.1497 0.4140 0.3096 0.2538 0.4400 0.4669 0.4423 0.2466 0.3680 0.6204 Columns 41 through 50 0.8794 0.2827 0.5550 0.0932 0.3351 0.3690 0.5590 0.9510 0.9498 0.1827

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

65 111 103 105 101 103 105 97 97 97 121 97 102 114 119 121

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!