How to convert row and column vectors of a symmetric matrix to zero if diagonal value is zero?

4 views (last 30 days)
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.

Accepted Answer

Krishna Kumar
Krishna Kumar on 23 Jun 2011
This would do it without loop- index=find(diag(your_matrix)==0); your_matrix(index,:)=0; your_matrix(:,index)=0;

More Answers (1)

Andrei Bobrov
Andrei Bobrov on 23 Jun 2011
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)

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!