Cody

Problem 6. Select every other element of a vector

Solution 2025170

Submitted on 17 Nov 2019 by Vaibhav Shende
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.9862 0.1405 0.3927 0.5112 0.7423

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.8165 0.7862 0.6822 0.5339 0.7810 0.3314 0.2858 0.6370 0.2632 0.5766 0.0433 0.9150 0.8816 0.1603 0.8948 0.9652 0.8986 0.7573 Columns 19 through 36 0.6818 0.3493 0.0718 0.1050 0.9006 0.2779 0.2196 0.1766 0.5320 0.6002 0.4667 0.3609 0.8319 0.7052 0.1278 0.9037 0.3023 0.4310 Columns 37 through 50 0.2503 0.6353 0.7647 0.3389 0.8716 0.0712 0.5512 0.3381 0.2933 0.3898 0.6514 0.0715 0.9004 0.2193

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