Cody

Problem 6. Select every other element of a vector

Solution 2854604

Submitted on 19 Aug 2020 by Siddhi Khasnis
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.4882 0.3153 0.7850 0.4857 0.6519 0.4882 0.3153 0.7850 0.4857 0.6519

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.5100 0.3618 0.5493 0.9173 0.1980 0.8691 0.1472 0.3282 0.0866 0.0582 0.2391 0.2522 0.2197 0.8907 0.8806 0.3861 0.7585 0.5965 Columns 19 through 36 0.0818 0.9891 0.3301 0.9737 0.9951 0.4700 0.0838 0.5055 0.2713 0.8265 0.0804 0.7930 0.3963 0.0785 0.7179 0.6161 0.7831 0.6479 Columns 37 through 50 0.6047 0.4406 0.4949 0.6097 0.1150 0.8693 0.0788 0.6331 0.8556 0.1849 0.4300 0.2103 0.7058 0.6994 Columns 1 through 18 0.5100 0.3618 0.5493 0.9173 0.1980 0.8691 0.1472 0.3282 0.0866 0.0582 0.2391 0.2522 0.2197 0.8907 0.8806 0.3861 0.7585 0.5965 Columns 19 through 36 0.0818 0.9891 0.3301 0.9737 0.9951 0.4700 0.0838 0.5055 0.2713 0.8265 0.0804 0.7930 0.3963 0.0785 0.7179 0.6161 0.7831 0.6479 Columns 37 through 50 0.6047 0.4406 0.4949 0.6097 0.1150 0.8693 0.0788 0.6331 0.8556 0.1849 0.4300 0.2103 0.7058 0.6994

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' 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!