d = diag(v,k)places the elements of vectorvon thekth diagonal.k=0represents the main diagonal,K> 0is above the main diagonal, andk<0is below the main diagonal.
Diagonal elements, specified as a vector. Ifvis a vector withNelements, thendiag(v,k)is a square matrix of orderN+abs(k)。
diag([])returns an empty matrix,[]。
Data Types:single|double|int8|INT16|INT32|int64|uint8|UINT16|uint32|uint64|logical|char Complex Number Support:Yes
A—Input matrix matrix
Input matrix.diag如果返回错误,如果ndims(A) > 2。
diag([])returns an empty matrix,[]。
Data Types:single|double|int8|INT16|INT32|int64|uint8|UINT16|uint32|uint64|logical|char Complex Number Support:Yes
k—Diagonal number 整数
Diagonal number, specified as an integer.k=0represents the main diagonal,K> 0is above the main diagonal, andk<0is below the main diagonal.
For anm-经过-nmatrix,k在范围内。例如,对于与ngreater thanm, thek=0main diagonal consists of the elements with indices(1,1),(2,2), ...,(m,m)。这k=1above the main diagonal consists of the elements with indices(1,2),(2,3), ...,(m,m+1)。这k=-1在主角下方由带有指数的元素组成(2,1),(3,2), ...,(M,M-1)。
If you supplyk, then it must be a real and scalar integer value.
For variable-size inputs that are variable-length vectors (1-by-: or :-by-1),diag:
Treats the input as a vector
返回沿指定对角线的输入向量的矩阵
For variable-size inputs that are not variable-length vectors,diag:
Treats the input as a matrix
Does not support inputs that are vectors at run time
返回可变长度向量
If the input is variable-size (:m-by-:n) and has shape 0-by-0 at run time, then the output is 0-by-1, not 0-by-0. However, if the input is a constant size 0-by-0, then the output is[]。
For variable-size inputs that are not variable-length vectors (1-by-: or :-by-1),diagtreats the input as a matrix from which to extract a diagonal vector. This behavior occurs even if the input array is a vector at run time. To forcediag要从不是1 by-的可变大小输入构建矩阵:或:-by-1,请使用:
If you supplyk, then it must be a real and scalar integer value.
For variable-size inputs that are variable-length vectors (1-by-: or :-by-1),diag:
Treats the input as a vector
返回沿指定对角线的输入向量的矩阵
For variable-size inputs that are not variable-length vectors,diag:
Treats the input as a matrix
Does not support inputs that are vectors at run time
返回可变长度向量
If the input is variable-size (:m-by-:n) and has shape 0-by-0 at run time, then the output is 0-by-1, not 0-by-0. However, if the input is a constant size 0-by-0, then the output is[]。
For variable-size inputs that are not variable-length vectors (1-by-: or :-by-1),diagtreats the input as a matrix from which to extract a diagonal vector. This behavior occurs even if the input array is a vector at run time. To forcediag要从不是1 by-的可变大小输入构建矩阵:或:-by-1,请使用:
diag(x(:))instead ofdiag(x)
diag(x(:),k)instead of诊断(x,k)
Thread-Based Environment Run code in the background using MATLAB®背景池or accelerate code with Parallel Computing Toolbox™ThreadPool。
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.