MATLAB: Sum of rand matrix equal to zero

sum of all is zero

Dear All,
I want to generate matrix A ,i.e. n by n random matrix but the sum(sum(A)) = zero. Help in this regard will be highly appreciated……..
Regards……….

Best Answer

Subtract the mean from the samples:
n=10; z=randn(n,n); z=z-sum(sum(z))/(n*n); sum(sum(z))