MATLAB: Vectorization

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

Best Answer

If A is an NxN matrix:
A(1:N+1:N*N) = 0;