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 2009. Insert certain elements into a vector.

Created by J-G van der Toorn

We start with vector V. Some values W will be inserted into V, at positions U.

Say, V contains [1 2 3 4 5] and W is [0 -1] while U is [2 4], then the function should return as a result [1 0 2 3 -1 4 5]. In other words, the values at the positions in which a new value is inserted shift to the end of the vector. And the indices indicated in U are the original indices, when no elements have been inserted yet.

Insertion at position one-after-the-last element of v just appends that value to the vector v.

Your task is to find the most efficient or elegant solution to code this in Matlab language.

(Eval and Regexp are not your friends this time.)


Problem Group

Solution Statistics

25 correct solutions 36 incorrect solutions
Last solution submitted on Feb 17, 2016

Problem Comments