You have a simple for loop over variable k, so inside the for loop, k is going to be a scalar. A(k,k) would then be a scalar. diag() applied to a scalar is going to return the same value. You can just skip the diag call,
M(k)=b(k)/A(k,k);
Note: more efficient would be to not use a loop, and instead use
M = b ./ diag(A);
... unless length(b) is not the same as the length of the diagonal of A.
