www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ContourPlotOfVectorFieldExample.m
%% Contour Plot of Vector Field % %% % Calculate the 2-D gradient of $x e^{-x^2-y^2}$ on a grid. % Copyright 2015 The MathWorks, Inc. v = -2:0.2:2; [x,y] = meshgrid(v); z = x .* exp(-x.^2 - y.^2); [px,py] = gradient(z,.2,.2); %% % Plot the contour lines and vectors in the same figure. contour(v,v,z) hold on quiver(v,v,px,py) hold off