How to correctly draw 2D vectors?

Hey there,
I want to match the velocity vector arrows with the blue line of the graphic. The velocity vectors should have the same magnitude as the points in the blue line, but I can't understand why they don't match.
I would like something like this:
But, I all got is this:
This is my code:
% X=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] %position on x axis
Y=[-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7]; %position on y axis
U=[2.19 3.79 8.00 13.15 16.64 16.97 17.11 17.25 17.34 17.25 13.27 8.00 3.58 1.79 0]; %velocity on x axis
V=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] %velocity on y axis
hold on;
plot(U,Y);
grid on
quiver(X,Y,U,V);
hold off

回答(1 个)

Add a ‘0’ to the quiver call to turn off the scaling:
quiver(X,Y,U,V,0)
That produces the plot you want. See the documentation on quiver for details.

类别

帮助中心File Exchange 中查找有关 Vector Fields 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by