How can I get the secondary diagonal of a matrix?

92 vues (au cours des 30 derniers jours)
Antonio Modugno
Antonio Modugno le 27 Oct 2020
Commenté : Antonio Modugno le 27 Oct 2020
for exaple:
A=rand(5,5)
diag(A)= main diagonal of matrix A
I want to take the elements A(1,5), A(2,4), A(3,3), A(4,2), A(5,1), (secondary diagonal), and put those ones into a vector without picking each element

Réponse acceptée

Stephen23
Stephen23 le 27 Oct 2020
diag(fliplr(A))

Plus de réponses (1)

KSSV
KSSV le 27 Oct 2020
Modifié(e) : KSSV le 27 Oct 2020
Read about diag. You can get diagonal elements by using that.
A = rand(5) ;
diag(A)
diag(A,-1)
diag(A,1)
May be you are looking for
iwant = diag(fliplr(A))

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Tags

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by