Cody

Problem 6. Select every other element of a vector

Solution 1839661

Submitted on 5 Jun 2019 by Chris Winnard
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.9875 0.2211 0.1417 0.8600 0.6673

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

y = Columns 1 through 18 0.2682 0.7724 0.2628 0.8694 0.8479 0.3255 0.1491 0.1948 0.6503 0.0342 0.2955 0.4059 0.4086 0.8095 0.8366 0.2933 0.3564 0.6370 Columns 19 through 36 0.7057 0.2742 0.3931 0.3561 0.8657 0.8212 0.4997 0.9821 0.4124 0.5408 0.0949 0.2828 0.8546 0.3369 0.8291 0.6210 0.0563 0.0960 Columns 37 through 50 0.9465 0.6940 0.4666 0.4215 0.7940 0.9158 0.0300 0.8228 0.4038 0.2304 0.1333 0.1990 0.7087 0.4210

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!