필터 지우기
필터 지우기

Finding the diagonal vector from a square matrix

조회 수: 1 (최근 30일)
Lily
Lily 2012년 9월 20일
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?

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 9월 20일
편집: Azzi Abdelmalek 2012년 9월 20일
A = [2 9 4; 4 9 2; 1 5 0]
fliplr(diag(flipud(A))')
  댓글 수: 4
Matt Fig
Matt Fig 2012년 9월 21일
Also, for any square matrix with N rows:
A(N:N-1:N^2-1)
Andrei Bobrov
Andrei Bobrov 2012년 9월 21일
A(numel(A)-size(A,1)+1:-2:size(A,1))

댓글을 달려면 로그인하십시오.

추가 답변 (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