Cody

Problem 6. Select every other element of a vector

Solution 106383

Submitted on 4 Jul 2012 by Yusuf
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))

ans = 0.2234 0.7983 0.1696 0.0287 0.8642

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

ans = Columns 1 through 6 0.6560 0.0984 0.4641 0.5965 0.4137 0.1568 Columns 7 through 12 0.1957 0.5475 0.3475 0.1156 0.7150 0.8828 Columns 13 through 18 0.7031 0.6881 0.0603 0.4868 0.1460 0.9605 Columns 19 through 24 0.7501 0.6179 0.0583 0.5450 0.1183 0.1474 Columns 25 through 30 0.0345 0.2577 0.6097 0.9097 0.4140 0.4564 Columns 31 through 36 0.1975 0.8383 0.3865 0.5404 0.2968 0.1182 Columns 37 through 42 0.9915 0.7584 0.1415 0.9658 0.3871 0.5812 Columns 43 through 48 0.1030 0.3944 0.2930 0.7382 0.7209 0.6774 Columns 49 through 50 0.8986 0.4411

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

ans = 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!