Cody

Problem 6. Select every other element of a vector

Solution 2096676

Submitted on 17 Jan 2020 by Courtney Carduner
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.9096 0.9293 0.8795 0.2473 0.7037

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.8473 0.5469 0.1013 0.0756 0.6596 0.7477 0.1286 0.3216 0.0755 0.8091 0.6854 0.4267 0.3347 0.3239 0.7937 0.2163 0.4335 0.2525 Columns 19 through 36 0.7130 0.3693 0.6441 0.3658 0.7938 0.3178 0.0339 0.9916 0.2153 0.1028 0.3558 0.7982 0.8851 0.7459 0.2299 0.5511 0.9939 0.3337 Columns 37 through 50 0.5564 0.5282 0.8481 0.7719 0.2336 0.0772 0.6762 0.5384 0.6047 0.7439 0.5044 0.2897 0.4410 0.4963

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!