I have a fixed sized array in Matlab. When I want to insert a new element I do the following:
- To make room first array element will be overwritten
- Every other element will be shifted at new location
index-1—left shift. - The new element will be inserted at the place of last element which becomes empty by shifting the elements.
I would like to do it without using any loops.
I’m not sure I understand your question, but I think you mean this:
That will insert the variable (or array)
newElemafter positionposin arrayA.Let me know if that works for you!
[Edit] Ok, looks like you actually just want to use the array as a shift register. You can do it like this:
This will take all elements from the 2nd to the last of
Aand added yournewElemvariable (or array) to the end.