Cody

Problem 6. Select every other element of a vector

Solution 2123211

Submitted on 9 Feb 2020 by Stefanos Charkoutsis
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.2755 0.3881 0.2246 0.6352 0.0730

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.1855 0.7323 0.9647 0.5028 0.1346 0.3664 0.3918 0.2603 0.6156 0.4682 0.9703 0.1403 0.4881 0.2810 0.4384 0.9071 0.4720 0.9805 Columns 19 through 36 0.2779 0.2022 0.5791 0.1709 0.5574 0.3008 0.9419 0.4381 0.0762 0.9255 0.4918 0.9888 0.9447 0.2464 0.0082 0.5529 0.3339 0.3291 Columns 37 through 50 0.7376 0.9252 0.8430 0.3735 0.2576 0.3476 0.8564 0.0435 0.2274 0.5389 0.1703 0.2961 0.4082 0.6139

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!