Insert an element into a list at a given position
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
listlib::insertAt(list, element, pos) inserts
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
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.
2 at the third place of the given
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
listlib::insertAt([1, 2, 3], 4, 1000), append([1, 2, 3], 4)
Any MuPAD® object
Given list enlarged with the inserted element