Cody

Problem 6. Select every other element of a vector

Solution 555555

Submitted on 11 Jan 2015 by John Nikas
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.3638 0.6305 0.3817 0.2222 0.5071 ans = []

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

y = Columns 1 through 9 0.3436 0.0998 0.5043 0.4408 0.1578 0.5372 0.6187 0.1191 0.9870 Columns 10 through 18 0.2524 0.9584 0.9438 0.8756 0.3916 0.4327 0.4055 0.2766 0.9480 Columns 19 through 27 0.5744 0.8693 0.3469 0.3198 0.6258 0.4054 0.4695 0.7379 0.5556 Columns 28 through 36 0.2636 0.3576 0.4338 0.1730 0.5092 0.0260 0.9414 0.9599 0.0408 Columns 37 through 45 0.8551 0.8790 0.9728 0.0762 0.2365 0.3962 0.1590 0.6846 0.8589 Columns 46 through 50 0.2490 0.9827 0.8306 0.1392 0.2867 ans = []

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 ans = []