MATLAB: Which MATLAB function can remove the diagonal elements of a NxN matrix

diagonalmatrix

Do you know which MATLAB function can do the following work: to remove the diagonal elements of a (N+1)x(N+1) matrix to generate a new NxN matrix.
For say, the old matrix is
[ 0 1 2 3
1 0 2 3
1 2 0 3
1 2 3 0 ]
the generated new matrix is
[ 1 2 3
1 2 3
1 2 3 ]

Best Answer

Your example doesn't add up, as Kenneth mentioned. However, in general you could do something like this:
A = [ 0 1 2 3
1 0 2 3
1 2 0 3
1 2 3 0 ];
A(logical(eye(size(A)))) = []; % Or A = A(~eye(size(A)))
A = reshape(A,4,3); % Or 3,4 or whatever.