Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Problem 801. Construct an index vector from two input vectors in vectorized fashion

Created by Christopher

Create an index vector defined by two input vectors, one defining the beginnings of one or more index ranges, and the other defining the ends of the ranges.

The difficult part is that for and while loops are disallowed. No looping! [I apologize for the rudimentary regexp test for 'for' 'while' and 'eval'.] My test cases scan for usage of these substrings, so choice of variable names is effectively restricted as well.

So given 2 input vectors x1 and x2, the desired output is a third vector y, containing [x1(1):x2(1) x1(2):x2(2) ... x1(end):x2(end)]


 x1 = [1 5 12];
 x2 = [2 8 21];


 y = [1 2 5 6 7 8 12 13 14 15 16 17 18 19 20 21]

Problem Group

Solution Statistics

40 correct solutions 57 incorrect solutions
Last solution submitted on Mar 20, 2016

Problem Comments

Solution Comments