vectorization
古いコメントを表示
hi,
is there a quick way to change the values of the diagonal of a matrix, instead of
for i = 1:length(A)
A(i,i) = 0;
end
thx
1 件のコメント
Andrei Bobrov
2011 年 12 月 8 日
A-diag(diag(A))
採用された回答
その他の回答 (1 件)
Sean de Wolski
2011 年 12 月 8 日
One way:
A = magic(100); %sample matrix
A(logical(speye(length(A)))) = 0;
Also diag if you're building a matrix
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!