Cody

Problem 6. Select every other element of a vector

Solution 1979695

Submitted on 17 Oct 2019 by Ngo Minh Ngoc
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.6565 0.1137 0.9033 0.7457 0.3069

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

y = Columns 1 through 18 0.2579 0.4157 0.4492 0.0455 0.2589 0.8785 0.5197 0.6451 0.4780 0.3262 0.0396 0.5590 0.0577 0.9731 0.4233 0.1897 0.1010 0.0939 Columns 19 through 36 0.3775 0.4080 0.1541 0.2479 0.7926 0.2048 0.1173 0.3115 0.9823 0.6317 0.7943 0.8479 0.9175 0.8232 0.2459 0.0277 0.5915 0.5001 Columns 37 through 50 0.2594 0.0246 0.2111 0.8924 0.2374 0.8312 0.5163 0.3124 0.9538 0.2807 0.7360 0.0048 0.5916 0.2171

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!