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 columns 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::swapCol(A, c1, c2)
linalg::swapCol(A, c1, c2, r1 .. r2)


linalg::swapCol(A, c1, c2) returns a copy of the matrix A with the columns with indices c1 and c2 interchanged.

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


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 column of A. The result is the following matrix:

linalg::swapCol(A, 1, 2)

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

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

The third row remains unchanged.



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

c1, c2

The column indices: positive integers less or equal to n

r1 .. r2

A range of row indices (positive integers less or equal to m)

Return Values

Matrix of the same domain type as A.

Was this topic helpful?