Cody

Problem 6. Select every other element of a vector

Solution 172693

Submitted on 5 Dec 2012 by Ryan
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 = Columns 1 through 3 0.890784007655189 0.962936276264628 0.294980995787596 Columns 4 through 5 0.861127005044056 0.933050947948683

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

y = Columns 1 through 3 0.0492585017772468 0.0260908796562839 0.768140019119022 Columns 4 through 6 0.992890073977056 0.864862798517452 0.919571424366564 Columns 7 through 9 0.416122832191584 0.709483453190131 0.365390716658231 Columns 10 through 12 0.397093722275284 0.291268857868005 0.241494194870644 Columns 13 through 15 0.0450181443720908 0.300233380945938 0.225465826522766 Columns 16 through 18 0.745743428098218 0.486981849222833 0.098892984231662 Columns 19 through 21 0.605097973512507 0.0074627675709068 0.954581365583357 Columns 22 through 24 0.535151762572922 0.0364381451493241 0.0787057766834933 Columns 25 through 27 0.494080304127943 0.434259750186277 0.220182751077122 Columns 28 through 30 0.851250602411298 0.327780674332683 0.320413758597688 Columns 31 through 33 0.919338975998711 0.623723907581535 0.284392724803199 Columns 34 through 36 0.972701390415358 0.356626360463221 0.787841938412074 Columns 37 through 39 0.263076317790112 0.598117336315718 0.960931371990253 Columns 40 through 42 0.546068757731171 0.893262977360803 0.00168150099589848 Columns 43 through 45 0.335410404527503 0.244157544698833 0.572589302763282 Columns 46 through 48 0.676989590306336 0.690933050728392 0.601259813713887 Columns 49 through 50 0.651469284216917 0.081408226460835

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!