Cody

Problem 6. Select every other element of a vector

Solution 719634

Submitted on 22 Aug 2015 by Keyur Vachhani
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))

ans = 0.3920 0.0759 0.5803 0.2128 0.9129

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

ans = Columns 1 through 18 0.5196 0.0859 0.3496 0.6879 0.5283 0.6900 0.9344 0.4216 0.0348 0.7636 0.8751 0.5328 0.6109 0.6295 0.1327 0.7780 0.7287 0.0522 Columns 19 through 36 0.1921 0.5533 0.8900 0.7032 0.6882 0.4143 0.4962 0.7086 0.7358 0.1862 0.8086 0.6988 0.1931 0.4529 0.8917 0.1304 0.3963 0.4733 Columns 37 through 50 0.6775 0.8739 0.9442 0.1014 0.3387 0.7450 0.3290 0.2061 0.8272 0.4130 0.6538 0.0504 0.2535 0.9981

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))

ans = 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!