This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Swap two rows in a matrix

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.


linalg::swapRow(A, r1, r2)
linalg::swapRow(A, r1, r2, c1 .. c2)


linalg::swapRow(A, r1, r2) returns a copy of the matrix A with the rows with indices r1 and r2 interchanged.

The effect of linalg::swapRow(A, r1, r2, c1.. c2) is that only the components from column c1 to column c2 of row r1 are interchanged with the corresponding components of row r2.


Example 1

We consider the following matrix:

A := matrix(3, 3, (i, j) -> 3*(i - 1) + j)

The following command interchanges the first and the second row of A. The result is the following matrix:

linalg::swapRow(A, 1, 2)

If only the components in the first two columns should be affected, we enter:

linalg::swapRow(A, 1, 2, 1..2)

The third column remains unchanged.



An m×n matrix of a domain of category Cat::Matrix

r1, r2

The row indices: positive integers less or equal to m

c1 .. c2

A range of column indices (positive integers less or equal to n)

Return Values

Matrix of the same domain type as A.

Was this topic helpful?