Cody

Problem 6. Select every other element of a vector

Solution 1904501

Submitted on 19 Aug 2019 by Mark Graham
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))

z = 1 0 1 0 1 0 1 0 1 0 y = 0.9593 0.1533 0.3354 0.2336 0.6040

2   Pass
x = rand(1,100); actual = everyOther(x); expected = x(1:2:length(x)); assert(isequal(actual, expected))

z = Columns 1 through 30 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 Columns 31 through 60 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 Columns 61 through 90 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 Columns 91 through 100 1 0 1 0 1 0 1 0 1 0 y = Columns 1 through 18 0.2855 0.5156 0.4544 0.3959 0.3600 0.4334 0.8295 0.8029 0.7992 0.6892 0.6527 0.9440 0.9738 0.7182 0.2492 0.8147 0.8916 0.8923 Columns 19 through 36 0.8095 0.8828 0.7337 0.1893 0.9549 0.6002 0.4299 0.6208 0.1757 0.7520 0.1785 0.4045 0.7967 0.1299 0.0332 0.3903 0.5432 0.2275 Columns 37 through 50 0.2581 0.9660 0.9900 0.7187 0.8470 0.9360 0.0377 0.8414 0.5487 0.1539 0.2561 0.5393 0.8035 0.1470

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))

z = Columns 1 through 30 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 Column 31 1 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!