Previous Up Next

5.49.18  Replacing part of a matrix or vector: REPLACE, replace

The REPLACE (or replace) command takes three arguments; either a matrix, a list of two indices, and another matrix, or a vector, a single index, and another vector.
REPLACE returns the first matrix (or vector) with the second matrix (or vector) placed at the location given by the indices, replacing the elements previously there. The second matrix (or vector) will be shrunk, if necessary, so that it fits in the first matrix (or vector).
Input:

REPLACE([[1,2,3],[4,5,6]],[0,1],[[5,6],[7,8]])

Output:

[[1,5,6],[4,7,8]]

Input:

REPLACE([[1,2,3],[4,5,6]],[1,2],[[7,8],[9,0]])

Output:

[[1,2,3],[4,5,7]]

Input:

REPLACE([4,1,-2,1,2,-1],2,[10,11])

Output:

[4,1,10,11,2,-1]

Input:

REPLACE([4,1,-2,1,2,-1],1,[10,11,13])

Output:

[4,10,11,13,2,-1]

Previous Up Next