Cody

Problem 6. Select every other element of a vector

Solution 1281576

Submitted on 5 Oct 2017 by Ratchet_Hamster
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.2985 0.2141 0.1494 0.1312 0.6585

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

y = Columns 1 through 17 0.5860 0.7438 0.1838 0.9529 0.0434 0.4680 0.8606 0.0999 0.3279 0.8672 0.7422 0.8733 0.2437 0.8101 0.4845 0.6667 0.4371 Columns 18 through 34 0.1753 0.4327 0.1141 0.0926 0.9680 0.2621 0.3604 0.8755 0.3038 0.8670 0.5529 0.9361 0.9876 0.7728 0.4422 0.0925 0.4427 Columns 35 through 50 0.5022 0.7150 0.5227 0.0834 0.0602 0.5014 0.9232 0.8431 0.1264 0.4342 0.5799 0.6148 0.8195 0.3448 0.4585 0.4629

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!