How to extract the diagonal of a given matrix?

8 ビュー (過去 30 日間)
Elruz Rahimli
Elruz Rahimli 2017 年 9 月 7 日
コメント済み: Elruz Rahimli 2017 年 9 月 7 日
How can I extract the diagonal of a given matrix with using size? I know we can do it directly with diag.
  5 件のコメント
José-Luis
José-Luis 2017 年 9 月 7 日
Read the documentation on ind2sub() and sub2ind(). Having done that and using the fact that the diagonal of a square matrix is where I == J (keeping the nomenclature from the documentation) would allow you to solve your problem.
Elruz Rahimli
Elruz Rahimli 2017 年 9 月 7 日
Thank you for the directions. I am doing it.
Too bad that I cannot upvote in the comments section.

サインインしてコメントする。

採用された回答

KL
KL 2017 年 9 月 7 日
A(sub2ind(size(A),1:size(A,1),1:size(A,2)))

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by