Cody

Problem 6. Select every other element of a vector

Solution 1878793

Submitted on 19 Jul 2019 by jinyu zhou
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.5270 0.1317 0.4143 0.7928 0.4679

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.6370 0.5777 0.2615 0.7964 0.8237 0.4723 0.2067 0.8437 0.7071 0.2345 0.1078 0.1617 0.1408 0.7224 0.9958 0.1872 0.9526 0.1518 Columns 19 through 36 0.4053 0.3420 0.0682 0.2544 0.1062 0.9004 0.9947 0.1025 0.9913 0.5564 0.1262 0.7337 0.4972 0.9032 0.7368 0.3919 0.1823 0.8889 Columns 37 through 50 0.2371 0.9572 0.6424 0.7861 0.5940 0.1332 0.8090 0.5145 0.7770 0.2607 0.6292 0.1288 0.1596 0.5581

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!