clear A for i = 1:N, for j = 1:N, A(i,j) = abs(i-j); end end

It is a good idea to clear the value of A before you start. Alternatively, you can do it this way:

A = zeros(N,N); for i = 1:N, for j = 1:N, A(i,j) = abs(i-j); end end