I’m trying to insert a value to a vector at specific indices, specified in another vector, and then displacing the other values accordingly.
E.g.
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 some straightforward way to do that, preferably avoiding a loop?
If you wanted the new values inserted as in your deleted comment, do this: