Cody

Problem 6. Select every other element of a vector

Solution 1917496

Submitted on 31 Aug 2019 by Lamour Haithem Firass
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.6189 0.5377 0.6002 0.4277 0.6952

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.4065 0.8515 0.4205 0.6980 0.1416 0.5590 0.8142 0.8179 0.7474 0.5661 0.7842 0.2378 0.9724 0.7560 0.4525 0.4313 0.1028 0.4324 Columns 19 through 36 0.3938 0.5460 0.5724 0.0621 0.3943 0.2466 0.7421 0.9164 0.2694 0.1185 0.3990 0.9893 0.3759 0.8348 0.3079 0.6205 0.3632 0.3631 Columns 37 through 50 0.5347 0.9549 0.1765 0.7295 0.8412 0.7093 0.4491 0.1906 0.3037 0.4140 0.3903 0.6904 0.6241 0.6313

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!