How do I specify the diagonal elements of a matrix?
39 ビュー (過去 30 日間)
古いコメントを表示
I have some values, taken from another matrix. How do I specify them to be the diagonals of a new matrix?
回答 (2 件)
Matt Tearle
2011 年 2 月 13 日
To do a subscripted assignment into the diagonal of a matrix, you can use linear indexing:
A(1:n+1:end) = v
(where v is an n-element vector and n is the number of rows of A). So, for example,
A(1:n+1:end) = diag(B)
copies the diagonal of B into A.
5 件のコメント
参考
カテゴリ
Help Center および File Exchange で Operating on Diagonal Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!