This example shows how to add a quiver plot over a contour plot.
Create 10 contours of the peaks function.
n = -2.0:.2:2.0; [X,Y,Z] = peaks(n); contour(X,Y,Z,10)
Use the gradient function to find the numerical gradient of matrix Z. Store 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);
Use the quiver function to display arrows over the contour plot indicating the gradient values.
hold on quiver(X,Y,U,V) hold off