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

2 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Krishna Kumar
Krishna Kumar le 23 Juin 2011
This would do it without loop- index=find(diag(your_matrix)==0); your_matrix(index,:)=0; your_matrix(:,index)=0;
  1 commentaire
Muhammad Shafique
Muhammad Shafique le 23 Juin 2011
Thanks a lot Krishna. How can we change the zeros on the diagonal to a certain value, instead?

Connectez-vous pour commenter.

Plus de réponses (1)

Andrei Bobrov
Andrei Bobrov le 23 Juin 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)
  2 commentaires
Matt Fig
Matt Fig le 23 Juin 2011
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.');

Connectez-vous pour commenter.

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by