I am trying to insert a value into a vector at specific indices specified in another vector, and then shift the other values accordingly.
eg.
Vector=[1 2 3 4 5] %vector of data
Idx=[2 4] %Indices at which to insert a value
Value to insert is X
NewVector=[1 X 2 X 3 4 5]
Is there an easy way to do this, preferably avoiding the loop?
source
share