Cody

Problem 6. Select every other element of a vector

Solution 176259

Submitted on 12 Dec 2012 by Andreas
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.4961 0.3890 0.3645 0.6784 0.8671

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

y = Columns 1 through 10 0.7688 0.6258 0.0129 0.0585 0.1110 0.2205 0.3233 0.2965 0.3868 0.8628 Columns 11 through 20 0.3018 0.3444 0.8068 0.3487 0.5406 0.9553 0.5385 0.4782 0.1426 0.9541 Columns 21 through 30 0.9309 0.4867 0.2108 0.8034 0.3865 0.9640 0.6749 0.1707 0.3580 0.0967 Columns 31 through 40 0.7206 0.3939 0.5066 0.9073 0.8289 0.9726 0.6825 0.1586 0.8570 0.1949 Columns 41 through 50 0.4799 0.8403 0.4412 0.4074 0.9682 0.8687 0.6413 0.5893 0.8945 0.4107

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