Cody

Problem 6. Select every other element of a vector

Solution 836347

Submitted on 23 Feb 2016 by Gene. Lin
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))

x = 0.1198 0.0190 0.6974 0.4957 0.2220

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

x = Columns 1 through 17 0.4605 0.9978 0.9902 0.1794 0.7151 0.8219 0.0258 0.4565 0.0434 0.9758 0.1910 0.8062 0.1168 0.0123 0.4060 0.4745 0.0651 Columns 18 through 34 0.7937 0.4876 0.2116 0.7464 0.3832 0.8711 0.4888 0.9060 0.8683 0.0047 0.4104 0.6572 0.5619 0.5934 0.0574 0.3542 0.9972 Columns 35 through 50 0.1896 0.2480 0.9213 0.3660 0.0344 0.6478 0.7259 0.2487 0.1397 0.6327 0.2166 0.9801 0.0105 0.8309 0.0569 0.9390

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

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