Cody

Problem 6. Select every other element of a vector

Solution 1650569

Submitted on 16 Oct 2018 by Jonas Rued
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.5349 0.0865 0.5701 0.4391 0.0726

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.3278 0.2244 0.7493 0.1545 0.0559 0.0342 0.5705 0.2598 0.0264 0.1202 0.8935 0.7539 0.5351 0.1611 0.6858 0.8950 0.6470 0.7475 Columns 19 through 36 0.4638 0.9922 0.4147 0.6800 0.6266 0.4238 0.4285 0.4932 0.4113 0.8861 0.4019 0.8352 0.5567 0.7740 0.2935 0.0226 0.7460 0.6615 Columns 37 through 50 0.9089 0.6881 0.5329 0.6138 0.7726 0.4236 0.1253 0.9231 0.3480 0.5879 0.8355 0.4398 0.9029 0.6038

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!