Cody

Problem 6. Select every other element of a vector

Solution 2001784

Submitted on 4 Nov 2019 by Ryan Peterson
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.0584 0.4533 0.8398 0.7010 0.1785

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.7858 0.2874 0.9001 0.7499 0.4681 0.1841 0.0129 0.0728 0.0217 0.7235 0.7962 0.3949 0.2593 0.7968 0.9104 0.3237 0.6003 0.5765 Columns 19 through 36 0.9747 0.0540 0.1418 0.1194 0.4723 0.8935 0.8931 0.5377 0.8515 0.4151 0.7373 0.7452 0.5072 0.3437 0.4807 0.3170 0.6955 0.3905 Columns 37 through 50 0.2415 0.1905 0.0145 0.3265 0.4683 0.9229 0.1668 0.6602 0.6561 0.6979 0.8434 0.2449 0.8135 0.2493

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!