Cody

Problem 6. Select every other element of a vector

Solution 2199626

Submitted on 8 Apr 2020 by Andrzej Mamczura
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.2232 0.2316 0.4750 0.8533 0.9187

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.1092 0.9962 0.4066 0.8733 0.1660 0.7766 0.4897 0.8070 0.3921 0.4752 0.9028 0.4983 0.3771 0.1403 0.7078 0.8507 0.9826 0.3752 Columns 19 through 36 0.7734 0.6316 0.9121 0.4431 0.3655 0.4569 0.4983 0.2549 0.1556 0.6936 0.9790 0.1798 0.2401 0.2711 0.1487 0.3492 0.1730 0.9320 Columns 37 through 50 0.8224 0.7801 0.2137 0.6573 0.1961 0.7432 0.7590 0.6731 0.4418 0.4885 0.0644 0.1318 0.9820 0.7713

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'

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!