This example shows how to add a quiver plot over a contour plot.
Create 10 contours of the
n = -2.0:.2:2.0; [X,Y,Z] = peaks(n); contour(X,Y,Z,10)
gradient function to find the numerical gradient of matrix
U as the gradient in the x-direction and
V as the gradient in the y-direction. Use a spacing of 0.2 between points in each direction.
[U,V] = gradient(Z,0.2);
quiver function to display arrows over the contour plot indicating the gradient values.
hold on quiver(X,Y,U,V) hold off