Cody

Problem 6. Select every other element of a vector

Solution 1359603

Submitted on 27 Nov 2017 by Sam Perry
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.9123 0.0077 0.4303 0.9232 0.8358

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

ans = Columns 1 through 18 0.5465 0.9255 0.7067 0.3826 0.7271 0.6022 0.6487 0.2094 0.7985 0.2077 0.8477 0.8676 0.1006 0.5559 0.2019 0.3693 0.3500 0.7597 Columns 19 through 36 0.2472 0.6209 0.0592 0.7061 0.3289 0.9701 0.6909 0.8124 0.0840 0.3919 0.9308 0.9628 0.6147 0.0773 0.1946 0.5726 0.1590 0.0983 Columns 37 through 50 0.8948 0.4101 0.3716 0.5676 0.4078 0.2530 0.9714 0.7540 0.1203 0.8369 0.4565 0.3983 0.2513 0.2023

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!