For the case using sobel kernel, multiply 1/8 to the resulted values:
[Gmag,Gdir] = imgradient(I, 'sobel');
Gmag_normalized = Gmag / 8;
The window (kernel) used in sobel filter is:
w = [1 0 -1; 2 0 -2; 1 0 -1];
The sum of the absolute value is 8 (=abs(1+2+1)+abs(-1-2-1)). Hence, the resulted values are enhanced by this factor due to the convolution. One needs to compensate this for the normalization. The idea is the same as moving average.