Cody

Problem 6. Select every other element of a vector

Solution 2981620

Submitted on 23 Sep 2020 by Brooke Gauthier
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.6125 0.9845 0.1600 0.5545 0.3056

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.4422 0.6326 0.8096 0.9535 0.5765 0.1206 0.4812 0.1289 0.1432 0.5407 0.3459 0.6522 0.8568 0.7243 0.0698 0.3880 0.6927 Columns 18 through 34 0.9239 0.0549 0.0022 0.3886 0.1500 0.8878 0.7006 0.4116 0.3280 0.9251 0.2676 0.9768 0.4519 0.2616 0.8664 0.2936 0.2133 Columns 35 through 50 0.3850 0.3329 0.9062 0.0854 0.9029 0.6910 0.0576 0.3298 0.7643 0.1247 0.1881 0.0804 0.5943 0.7625 0.0937 0.6025

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!