Cody

Problem 6. Select every other element of a vector

Solution 2643559

Submitted on 2 Jul 2020 by Nayuan Lian
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.6528 0.3642 0.8071 0.6564 0.0860

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.6658 0.6185 0.0688 0.0806 0.3976 0.8921 0.3718 0.2832 0.4217 0.0644 0.2970 0.3548 0.3563 0.9054 0.2550 0.2808 0.6052 0.0251 Columns 19 through 36 0.1323 0.7472 0.4563 0.0047 0.2818 0.6522 0.5700 0.4673 0.8403 0.1156 0.3621 0.5782 0.3191 0.0685 0.7768 0.5109 0.7342 0.7393 Columns 37 through 50 0.7903 0.4162 0.9732 0.2310 0.4968 0.3508 0.5345 0.2833 0.5603 0.4151 0.8448 0.1224 0.1723 0.2807

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!