I have a huge matrix to A to solve for Ax=B. There are some rows with zero elements in A and I want to modify the diagonal for these rows. So how can I fast find these rows with all zero elements? for loop is rather slow.
2 ビュー (過去 30 日間)
古いコメントを表示
I have a huge matrix to A to solve for Ax=B. There are some rows with zero elements in A and I want to modify the diagonal for these rows. So how can I fast find these rows with all zero elements? for loop is rather slow.
0 件のコメント
回答 (2 件)
Andrei Bobrov
2019 年 3 月 13 日
編集済み: Andrei Bobrov
2019 年 3 月 13 日
"How to set diagonal as 1 for the row with all zero elements?"
A = A + diag(~diag(A));
or
n = all(A==0,2);
A = A + diag(n);
or
n = all(A==0,2);
ex = (1:size(A,1)+1:numel(A))';
A(ex) = A(ex) + n;
参考
カテゴリ
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!