Cody

Problem 6. Select every other element of a vector

Solution 2643256

Submitted on 2 Jul 2020 by Vaibhav Mishra
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.0516 0.4254 0.8532 0.6508 0.3140

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.7648 0.9768 0.6309 0.6658 0.2228 0.2757 0.7820 0.2869 0.1689 0.5822 0.5033 0.8669 0.5382 0.9701 0.9389 0.2382 0.3386 0.7832 Columns 19 through 36 0.2393 0.6276 0.8898 0.8087 0.7919 0.4467 0.1846 0.4878 0.9672 0.6304 0.7509 0.8833 0.8553 0.6433 0.8300 0.3866 0.5917 0.1467 Columns 37 through 50 0.1515 0.1157 0.9953 0.6414 0.1555 0.6185 0.6362 0.1886 0.2682 0.8053 0.2292 0.0915 0.2872 0.1158

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!