Cody

Problem 6. Select every other element of a vector

Solution 2674073

Submitted on 10 Jul 2020 by Matthias Saurer
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.8577 0.5364 0.9756 0.2980 0.8577

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.3750 0.3346 0.5200 0.5895 0.6872 0.4630 0.9094 0.7919 0.6076 0.8051 0.0935 0.6086 0.7012 0.5168 0.5316 0.6528 0.8508 Columns 18 through 34 0.3215 0.1767 0.6749 0.9409 0.7353 0.5443 0.9746 0.6840 0.1551 0.9156 0.0974 0.4961 0.4538 0.7499 0.5721 0.7844 0.4702 Columns 35 through 50 0.2093 0.5361 0.2296 0.1159 0.7613 0.6886 0.8041 0.8761 0.9376 0.4101 0.3929 0.3355 0.5816 0.8818 0.6610 0.3369

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!