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!