Cody

Problem 6. Select every other element of a vector

Solution 2270727

Submitted on 11 May 2020 by Russell Jones
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.4462 0.3721 0.1156 0.6818 0.4678

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.9419 0.4788 0.9054 0.7836 0.4095 0.0025 0.3319 0.5866 0.0153 0.1644 0.5331 0.9831 0.5127 0.3946 0.4855 0.6666 0.1999 Columns 18 through 34 0.8416 0.9221 0.3376 0.6444 0.6587 0.2424 0.4596 0.8804 0.9849 0.7279 0.6109 0.3455 0.3174 0.0212 0.9708 0.8305 0.4355 Columns 35 through 50 0.2388 0.5353 0.8837 0.7670 0.2806 0.6207 0.7128 0.9872 0.7438 0.7936 0.6642 0.3353 0.9844 0.0861 0.8099 0.0121

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!