Cody

Problem 6. Select every other element of a vector

Solution 1989789

Submitted on 24 Oct 2019 by Nabeel Ahmad
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.0061 0.4294 0.3710 0.9494 0.1258

2   Pass
x = rand(1,100); actual = everyOther(x); expected = x(1:2:length(x)); assert(isequal(actual, expected))

y = Columns 1 through 17 0.9342 0.2174 0.0456 0.2024 0.6979 0.9187 0.1871 0.3651 0.5805 0.1925 0.6159 0.9235 0.8240 0.6153 0.5776 0.2806 0.7765 Columns 18 through 34 0.7813 0.0418 0.4437 0.3730 0.9495 0.5127 0.1081 0.6786 0.4440 0.9598 0.4769 0.4858 0.0748 0.6441 0.2504 0.8547 0.4827 Columns 35 through 50 0.2462 0.2158 0.5316 0.9043 0.2187 0.1176 0.4633 0.3565 0.7968 0.2372 0.2343 0.4766 0.6802 0.6017 0.7868 0.0437

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!