Cody

Problem 6. Select every other element of a vector

Solution 1998875

Submitted on 1 Nov 2019 by Son Pham
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.6824 0.3342 0.3531 0.1328 0.8220

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.6772 0.2399 0.9955 0.3634 0.4385 0.7517 0.9186 0.5762 0.1334 0.3121 0.0242 0.8942 0.0672 0.2810 0.1816 0.4365 0.0376 0.5743 Columns 19 through 36 0.1780 0.5812 0.4039 0.3261 0.0207 0.6101 0.1703 0.9108 0.8374 0.0524 0.2543 0.7633 0.3463 0.6904 0.2235 0.5276 0.8314 0.4249 Columns 37 through 50 0.2651 0.8965 0.3460 0.1184 0.5066 0.9419 0.0084 0.2323 0.1515 0.4449 0.9457 0.5475 0.3659 0.5251

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!