How to extract the diagonal of a given matrix?

6 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by