Cody

Problem 6. Select every other element of a vector

Solution 1354672

Submitted on 23 Nov 2017 by David Hill
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.8075 0.9160 0.6662 0.8867 0.7707

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

ans = Columns 1 through 18 0.9733 0.1206 0.1271 0.8175 0.3747 0.4626 0.9222 0.5990 0.2019 0.7946 0.0276 0.3605 0.1419 0.3638 0.8379 0.4312 0.7940 0.9826 Columns 19 through 36 0.1179 0.6818 0.2636 0.3742 0.9534 0.2170 0.1771 0.2911 0.1211 0.5974 0.3284 0.5283 0.8794 0.9936 0.2776 0.1892 0.9010 0.5816 Columns 37 through 50 0.7816 0.9785 0.9279 0.4549 0.6031 0.0559 0.9069 0.9119 0.2121 0.0604 0.8558 0.5071 0.0066 0.8050

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!