This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Change a column of 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::setCol(A, p, c)


linalg::setCol(A, p, c) returns a copy of matrix A with the p-th column replaced by the column vector .

If c is a list with at most m elements, then c is converted into a column vector. An error message is returned if the conversion is not possible (e.g., if an element of the list cannot be converted into an object of the component ring of A; see Example 2).


Example 1

We define a matrix over the rationals:

MatQ := Dom::Matrix(Dom::Rational): 
A := MatQ([[1, 2], [3, 2]])

and replace the 2nd column by the 2×1 zero vector:

linalg::setCol(A, 2, MatQ([0, 0]))

Example 2

We create the 2×2 zero matrix over 6:

B := Dom::Matrix(Dom::IntegerMod(6))(2, 2)

and replace the 2nd column by the vector . We give the column vector in form of a list. Its elements are converted implicitly into objects of the component ring of B:

linalg::setCol(B, 2, [1, -1])

The following input leads to an error message because the number 1/3 can not be converted into an object of type Dom::IntegerMod(6):

linalg::setCol(B, 1, [1/3, 0])
Error: Invalid column vector. [linalg::setCol]



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


A column vector, or a list that can be converted into a column vector of the domain Dom::Matrix(R), where R is the component ring of A (a column vector is an m×1 matrix)

Return Values

Matrix of the same domain type as A.

Was this topic helpful?