This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Combine Contour Plot and Quiver Plot

This example shows how to combine a contour plot and a quiver plot using the hold function.

Plot 10 contours of xe-x2-y2 over a grid from -2 to 2 in the x and y directions.

[X,Y] = meshgrid(-2:0.2:2);
Z = X .* exp(-X.^2 - Y.^2);

Calculate the 2-D gradient of Z using the gradient function. The gradient function returns U as the gradient in the x-direction and V as the gradient in the y-direction. Display arrows indicating the gradient values using the quiver function.

[U,V] = gradient(Z,0.2,0.2);
hold on
hold off

See Also