Cody

Problem 6. Select every other element of a vector

Solution 3827838

Submitted on 25 Nov 2020 by Vanilo Antonio
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.2833 0.0358 0.8709 0.5565 0.8993

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.0502 0.0436 0.4255 0.2256 0.0768 0.9036 0.6803 0.7279 0.7852 0.8874 0.1057 0.5823 0.8079 0.7581 0.4445 0.8416 0.4610 Columns 18 through 34 0.6667 0.3509 0.5669 0.2634 0.0329 0.2455 0.7236 0.1077 0.3171 0.6896 0.0473 0.1912 0.6843 0.1122 0.3576 0.4977 0.1684 Columns 35 through 50 0.8763 0.8957 0.3105 0.2468 0.5850 0.5892 0.1166 0.6869 0.6162 0.2318 0.7937 0.8460 0.0537 0.4907 0.1622 0.7363

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!