How to convert row and column vectors of a symmetric matrix to zero if diagonal value is zero?
조회 수: 2 (최근 30일)
이전 댓글 표시
I have symmetric matrices of large size. I need to ensure that if there are any zeros on the main diagonal, then their corresponding row and column vectors are also set to zero. Please help.
댓글 수: 0
채택된 답변
Krishna Kumar
2011년 6월 23일
This would do it without loop- index=find(diag(your_matrix)==0); your_matrix(index,:)=0; your_matrix(:,index)=0;
추가 답변 (1개)
Andrei Bobrov
2011년 6월 23일
dg = diag(your_matrix);
your_matrix(dg*dg'==0)=0
dg = diag(your_matrix);
l1 = dg == 0;
your_matrix(diag(l1)==1) = rand(nnz(l1),1)
댓글 수: 2
Matt Fig
2011년 6월 23일
I like your first approach, Andrei. This is along the same line, and faster for larger arrays.
B1 = logical(diag(A));
B1 = bsxfun(@times,bsxfun(@times,A,B1),B1.');
참고 항목
카테고리
Help Center 및 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!