Cody

Problem 6. Select every other element of a vector

Solution 1934478

Submitted on 13 Sep 2019 by Vu Thanh Nam
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.6947 0.0701 0.6725 0.0012 0.5107

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.0510 0.8389 0.8087 0.7035 0.4238 0.2462 0.9005 0.9213 0.7946 0.3747 0.5122 0.0967 0.9904 0.5088 0.8942 0.6021 0.5095 0.4580 Columns 19 through 36 0.9039 0.4719 0.8349 0.5352 0.7083 0.7984 0.9983 0.9565 0.1177 0.9857 0.3525 0.2343 0.9748 0.5768 0.7238 0.1586 0.5419 0.3162 Columns 37 through 50 0.2026 0.7106 0.1443 0.2056 0.7978 0.9629 0.5545 0.0134 0.4996 0.8854 0.6918 0.0565 0.8926 0.3833

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!