Cody

Problem 6. Select every other element of a vector

Solution 162198

Submitted on 14 Nov 2012 by T.D.
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.4893 0.9001 0.1112 0.3897 0.4039

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

y = Columns 1 through 6 0.1320 0.9561 0.0598 0.3532 0.0154 0.1690 Columns 7 through 12 0.7317 0.4509 0.2963 0.1890 0.1835 0.6256 Columns 13 through 18 0.0811 0.7757 0.4359 0.3063 0.5108 0.7948 Columns 19 through 24 0.3786 0.5328 0.9390 0.5502 0.5870 0.3012 Columns 25 through 30 0.2305 0.1948 0.1707 0.4357 0.9234 0.1848 Columns 31 through 36 0.9797 0.1111 0.4087 0.2622 0.7112 0.1174 Columns 37 through 42 0.3188 0.5079 0.2625 0.0292 0.7303 0.5785 Columns 43 through 48 0.4588 0.5468 0.2316 0.6241 0.3955 0.9880 Columns 49 through 50 0.8852 0.7962

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!