Cody

# Problem 6. Select every other element of a vector

Solution 39898

Submitted on 13 Feb 2012 by Vishwanathan Iyer
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.0406 0.6826 0.5384 0.3505 0.7275

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.6937 0.4058 0.3914 0.2608 0.5385 0.9229 Columns 7 through 12 0.4801 0.1765 0.8337 0.2714 0.6062 0.7465 Columns 13 through 18 0.9232 0.4986 0.2342 0.1176 0.8025 0.8518 Columns 19 through 24 0.7760 0.0176 0.6704 0.7606 0.2662 0.8964 Columns 25 through 30 0.3978 0.9956 0.0189 0.7074 0.0678 0.9736 Columns 31 through 36 0.3596 0.3548 0.5411 0.6580 0.1526 0.5397 Columns 37 through 42 0.5571 0.1714 0.7585 0.7282 0.3703 0.8676 Columns 43 through 48 0.7805 0.6696 0.9487 0.1258 0.1234 0.6282 Columns 49 through 50 0.7737 0.7457

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

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!