vectorization
1 次查看(过去 30 天)
显示 更早的评论
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 个)
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!