Use of the Sobel Filter for Image Gradient [MATLAB] I am using the Sobel filter for an RGB image. I have found two different ways to do that and the results look a little different. What is the difference between these two methods?

Method 1

 sbl=fspecial('Sobel');
 sbl_red=imfilter(Image(:,:,1));


Method 2

 [magred,dirred]=imgradient(Image(:,:,1),'Sobel')


Is there an advantage over one of the two methods? I am trying to find a structure of the image that is parallel to the x axis.
Well, if you go through the documentation of fspecial() you'd see it returns the following filter:

h = fspecial('sobel') returns a 3-by-3 filter h that emphasizes horizontal edges using the smoothing effect by approximating a vertical gradient. To emphasize vertical edges, transpose the filter h'.

[ 1  2  1 
  0  0  0 
 -1 -2 -1 ]


Namely in the way you applied it above you only got the vertical element of the gradient.

While imgradient() returns the image of the magnitude of the Gradient (Which has Vertical and Horizontal elements) and its direction.