How to extract the diagonal of a given matrix?

6 Ansichten (letzte 30 Tage)
Elruz Rahimli
Elruz Rahimli am 7 Sep. 2017
Kommentiert: Elruz Rahimli am 7 Sep. 2017
How can I extract the diagonal of a given matrix with using size? I know we can do it directly with diag.
  5 Kommentare
José-Luis
José-Luis am 7 Sep. 2017
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 am 7 Sep. 2017
Thank you for the directions. I am doing it.
Too bad that I cannot upvote in the comments section.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KL
KL am 7 Sep. 2017
A(sub2ind(size(A),1:size(A,1),1:size(A,2)))

Weitere Antworten (0)

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by