indexing diagonal elements of a matrix in a loop
이전 댓글 표시
I have an n x n matrix, some of its diagonals are zeros. I need to eliminate the rows and columns corresponding to the diagonal zeros in a loop and retain all other elements. ie, if A=[0 3 5 6 5;3 0 4 7 8;7 9 1 0 3;2 4 6 0 8;1 4 5 7 6],after elimination of rows and columns corresponding to diagonal zeros the answer should be, ans=[1 3;5 6]
anyone please help with appropriate code.
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2013년 6월 2일
ii = find(diag(A));
out = A(ii,ii);
카테고리
도움말 센터 및 File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!