Cody

Problem 6. Select every other element of a vector

Solution 557653

Submitted on 14 Jan 2015 by Paul Kassebaum
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.8181 0.5466 0.1591 0.4302 0.8992

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

y = Columns 1 through 9 0.9535 0.0339 0.4212 0.3581 0.8662 0.1237 0.1570 0.3819 0.1562 Columns 10 through 18 0.2324 0.6003 0.5522 0.4601 0.9941 0.7507 0.7571 0.2337 0.1249 Columns 19 through 27 0.9262 0.1162 0.5001 0.6532 0.5947 0.4618 0.5241 0.5570 0.8251 Columns 28 through 36 0.9748 0.4535 0.4697 0.2196 0.0282 0.9211 0.3099 0.0357 0.4594 Columns 37 through 45 0.5903 0.0902 0.6976 0.1628 0.1034 0.8782 0.9478 0.2628 0.7205 Columns 46 through 50 0.7247 0.0346 0.8684 0.2873 0.4323

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!