Cody

Problem 6. Select every other element of a vector

Solution 301825

Submitted on 11 Aug 2013 by SAJJAD
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.6609 y = 0.6609 0 0.8908 y = 0.6609 0 0.8908 0 0.7690 y = 0.6609 0 0.8908 0 0.7690 0 0.9283 y = 0.6609 0 0.8908 0 0.7690 0 0.9283 0 0.0170 y = 0.6609 0.8908 0.7690 0.9283 0.0170

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

y = 0.8627 y = 0.8627 0 0.8449 y = 0.8627 0 0.8449 0 0.5523 y = 0.8627 0 0.8449 0 0.5523 0 0.0320 y = 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Column 11 0.4896 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 13 0.4896 0 0.1231 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 15 0.4896 0 0.1231 0 0.1465 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 17 0.4896 0 0.1231 0 0.1465 0 0.0427 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 19 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Column 21 0.6952 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 23 0.6952 0 0.5358 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 25 0.6952 0 0.5358 0 0.1239 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 27 0.6952 0 0.5358 0 0.1239 0 0.8530 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 29 0.6952 0 0.5358 0 0.1239 0 0.8530 0 0.2703 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 30 0.6952 0 0.5358 0 0.1239 0 0.8530 0 0.2703 0 Column 31 0.5650 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 30 0.6952 0 0.5358 0 0.1239 0 0.8530 0 0.2703 0 Columns 31 through 33 0.5650 0 0.4170 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 30 0.6952 0 0.5358 0 0.1239 0 0.8530 0 0.2703 0 Columns 31 through 35 0.5650 0 0.4170 0 0.9479 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 30 0.6952 0 0.5358 0 0.1239 0 0.8530 0 0.2703 0 Columns 31 through 37 0.5650 0 0.4170 0 0.9479 0 0.1057 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 30 0.6952 0 0.5358 0 0.1239 0 0.8530 0 0.2703 0 Columns 31 through 39 0.5650 0 0.4170 0 0.9479 0 0.1057 0 0.1665 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 30 0.6952 0 0.5358 0 0.1239 0 0.8530 0 0.2703 0 Columns 31 through 40 0.5650 0 0.4170 0 0.9479 0 0.1057 0 0.1665 0 Column 41 0.5737 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 30 0.6952 0 0.5358 0 0.1239 0 0.8530 0 0.2703 0 Columns 31 through 40 0.5650 0 0.4170 0 0.9479 0 0.1057 0 0.1665 0 Columns 41 through 43 0.5737 0 0.9312 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 30 0.6952 0 0.5358 0 0.1239 0 0.8530 0 0.2703 0 Columns 31 through 40 0.5650 0 0.4170 0 0.9479 0 0.1057 0 0.1665 0 Columns 41 through 45 0.5737 0 0.9312 0 0.7378 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 30 0.6952 0 0.5358 0 0.1239 0 0.8530 0 0.2703 0 Columns 31 through 40 0.5650 0 0.4170 0 0.9479 0 0.1057 0 0.1665 0 Columns 41 through 47 0.5737 0 0.9312 0 0.7378 0 0.8604 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 30 0.6952 0 0.5358 0 0.1239 0 0.8530 0 0.2703 0 Columns 31 through 40 0.5650 0 0.4170 0 0.9479 0 0.1057 0 0.1665 0 Columns 41 through 49 0.5737 0 0.9312 0 0.7378 0 0.8604 0 0.9844 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 30 0.6952 0 0.5358 0 0.1239 0 0.8530 0 0.2703 0 Columns 31 through 40 0.5650 0 0.4170 0 0.9479 0 0.1057 0 0.1665 0 Columns 41 through 50 0.5737 0 0.9312 0 0.7378 0 0.8604 0 0.9844 0 Column 51 0.7856 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 30 0.6952 0 0.5358 0 0.1239 0 0.8530 0 0.2703 0 Columns 31 through 40 0.5650 0 0.4170 0 0.9479 0 0.1057 0 0.1665 0 Columns 41 through 50 0.5737 0 0.9312 0 0.7378 0 0.8604 0 0.9844 0 Columns 51 through 53 0.7856 0 0.1776 y = Columns 1 through 10 0.8627 0 0.8449 0 0.5523 0 0.0320 0 0.3624 0 Columns 11 through 20 0.4896 0 0.1231 0 0.1465 0 0.0427 0 0.2819 0 Columns 21 through 30 0.6952 0 0.5358 0 0.1239 0 0.8530 0 0.2703 0 Columns 31 through 40 0.5650 0 0.4170 0 0.9479 0 0.1057 0 0.1665 0 Columns 41 through 50 0.5737 0 0.9312 0 0.7378 0 0.8604 0 0.9844 0 ...

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 = A y = A o y = A o g y = A o g i y = A o g i e y = A o g i e g y = A o g i e g i y = A o g i e g i a y = A o g i e g i a a y = A o g i e g i a a a y = A o g i e g i a a a y y = A o g i e g i a a a y a y = A o g i e g i a a a y a f y = A o g i e g i a a a y a f r y = A o g i e g i a a a y a f r w y = A o g i e g i a a a y a f r w y y = Aogiegiaaayafrwy