From: us on
Hafsa <qureshi.hafsa(a)gmail.com> wrote in message <cfc282bd-2f4d-4625-9f18-7da3641ae43d(a)f8g2000yqn.googlegroups.com>...
> what would be the shortest way to replace element at index (i, j) of a
> 2-D matrix A by abs(i-j)?

one of the solutions

m=-magic(3);
m(1,1)=abs(m(1,1))
% -or- in one shot
m=abs(m)

us