Cody

Problem 6. Select every other element of a vector

Solution 35671

Submitted on 9 Feb 2012 by Jos (10584)
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

This solution is outdated. To rescore this solution, sign in.

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.0474 0.7360 0.5449 0.8936 0.3037

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

y = Columns 1 through 6 0.1955 0.7218 0.5824 0.9227 0.2859 0.9848 Columns 7 through 12 0.8390 0.4706 0.2691 0.5039 0.3077 0.4756 Columns 13 through 18 0.7881 0.6685 0.0216 0.3008 0.9809 0.8008 Columns 19 through 24 0.5975 0.9437 0.7284 0.0259 0.6463 0.3723 Columns 25 through 30 0.8295 0.3725 0.8726 0.6685 0.6539 0.4067 Columns 31 through 36 0.9337 0.4845 0.4170 0.9880 0.3889 0.2467 Columns 37 through 42 0.8828 0.5583 0.1489 0.4504 0.8997 0.8825 Columns 43 through 48 0.6732 0.1228 0.2753 0.2834 0.8266 0.4979 Columns 49 through 50 0.8344 0.5747

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!