Cody

Problem 6. Select every other element of a vector

Solution 191946

Submitted on 16 Jan 2013 by Vieniava
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.0244 0.3175 0.9569 0.4579 0.7639

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

ans = Columns 1 through 10 0.7406 0.1059 0.4633 0.0985 0.1750 0.6660 0.5166 0.1536 0.5409 0.0366 Columns 11 through 20 0.7486 0.5250 0.5464 0.4151 0.2554 0.9237 0.9326 0.9211 0.5774 0.2576 Columns 21 through 30 0.2287 0.7673 0.7152 0.4190 0.8161 0.8145 0.8523 0.6357 0.4440 0.8667 Columns 31 through 40 0.3551 0.2242 0.6050 0.1422 0.4211 0.7258 0.8416 0.5710 0.9574 0.9246 Columns 41 through 50 0.3736 0.6401 0.0451 0.3474 0.3839 0.0216 0.8006 0.8131 0.6173 0.5301

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!