Insert an element into a list at a given position
This functionality does not run in MATLAB.
listlib::insertAt(list, element, <pos>)
listlib::insertAt(list, element, pos) inserts element into list at position pos.
With the function listlib::insertAt any element can be inserted into any list at a specified place.
The third argument (the "insert index") determines the place to insert the element into the given list.
If the insert index is less than 1 the element is inserted in front of the list. If the insertion index is greater than nops(list) the element is appended to the list. To append an element to a list the kernel function append is faster.
If no third argument is given, the given element is inserted in front of the list.
If the argument element is a list too, the elements of this list will be inserted (or appended) instead of the whole list by preserving the order.
Insertion 2 at the third place of the given list:
listlib::insertAt([1, 1, 1], 2, 3)
Insertion of an element in front of a list. The third argument is optional in this case:
listlib::insertAt([1, 1, 3, 1], 2, 0), listlib::insertAt([1, 1, 3, 1], 2)
Appending of an element. This could be done faster with append:
listlib::insertAt([1, 2, 3], 4, 1000), append([1, 2, 3], 4)