Cody

Problem 6. Select every other element of a vector

Solution 1409950

Submitted on 8 Jan 2018 by MOHIT
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.2412 0.3946 0.8982 0.6013 0.2992

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.1765 0.9188 0.5284 0.2010 0.5508 0.1209 0.1311 0.3541 0.4701 0.0428 0.4288 0.5771 0.6918 0.4142 0.2228 0.6656 0.7580 0.7474 Columns 19 through 36 0.6134 0.9699 0.2336 0.8962 0.8305 0.4145 0.1495 0.1789 0.7070 0.4334 0.2617 0.5309 0.7380 0.1637 0.8751 0.6026 0.6074 0.1644 Columns 37 through 50 0.6461 0.4354 0.7659 0.3507 0.7241 0.2195 0.2626 0.6223 0.1650 0.1717 0.3602 0.4564 0.5802 0.4599

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!