MATLAB: How to erase the diagonal elements of a matrix (in one line)

accepted wrong answerindexingmatrixmatrix manipulation

Let A be a square [NxN] matrix, I want to get an [N x N-1] matrix A' with diagonal elements erased and remaining elements shifted left. Is it possible to do so in one line of code?
I tried linear indexing:
A(1:N+1:end)=[];
but it returns a vector instead of a matrix.

Best Answer

I know that this violates the "one line" requirement, but a transpose makes the task easy:
>> X = [1,2,3;4,5,6;7,8,9]
X =
1 2 3
4 5 6
7 8 9
>> Y = X.';
>> reshape(Y(eye(3)'~=1),2,3).'
ans =
2 3
4 6
7 8