How to convert row and column vectors of a symmetric matrix to zero if diagonal value is zero?
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (1)
Andrei Bobrov
am 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)
2 Kommentare
Muhammad Shafique
am 23 Jun. 2011
Matt Fig
am 23 Jun. 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.');
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!