Borrar filtros
Borrar filtros

Finding the diagonal vector from a square matrix

1 visualización (últimos 30 días)
Lily
Lily el 20 de Sept. de 2012
Hi
I'm trying to find the diagonal of an square matrix but NOT the diagonal vector of the matrix from left to right. I'm trying to find the diagonal of an matrix fram right to left. Below is an example of what I'm trying to achieve:
A = [2 9 4; 4 9 2; 1 5 0];
diagA = diag(A); %Diagonal of the A matrix from left to right
%THE ANSWER: digA = [2 9 0]'
But what I'm trying to get is the diagonal from the A matrix from right to left for [4 9 1]
Is this possible? Can you please help me?

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 20 de Sept. de 2012
Editada: Azzi Abdelmalek el 20 de Sept. de 2012
A = [2 9 4; 4 9 2; 1 5 0]
fliplr(diag(flipud(A))')
  4 comentarios
Matt Fig
Matt Fig el 21 de Sept. de 2012
Also, for any square matrix with N rows:
A(N:N-1:N^2-1)
Andrei Bobrov
Andrei Bobrov el 21 de Sept. de 2012
A(numel(A)-size(A,1)+1:-2:size(A,1))

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Operating on Diagonal Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by