Cody

Problem 6. Select every other element of a vector

Solution 1747974

Submitted on 11 Mar 2019 by Daniel Cooper
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.9028 0.9969 0.0400 0.5737 0.1351

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.7562 0.5196 0.2527 0.2649 0.6792 0.9798 0.7419 0.2441 0.7420 0.4706 0.3384 0.3099 0.8417 0.9223 0.8809 0.8950 0.7051 0.2602 Columns 19 through 36 0.0516 0.4452 0.6051 0.8041 0.5610 0.3549 0.6558 0.2489 0.1847 0.4688 0.0950 0.9316 0.3915 0.8777 0.0505 0.6819 0.2397 0.5209 Columns 37 through 50 0.0425 0.0351 1.0000 0.1499 0.2847 0.1300 0.6844 0.6862 0.0484 0.4827 0.9515 0.4185 0.1107 0.3874

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'