MATLAB: 1-d gradient

gradient convlution

can i use covlution to get the same result of 1-d gradient
Screenshot (58).png
Screenshot (59).png

Best Answer

Your question contains the answer already. If the data is a vector, conv is sufficient instead of conv2:
x = rand(1, 10)
dx_1 = gradient(x)
dx_2 = conv(x, [0.5, 0, -0.5], 'same')
The first and last element of dx_2 differ from dx_1, but you can adjust it with the one-sided quotient of differences easily.