Clear Filters
Clear Filters

Quiver plot - vector direction

2 views (last 30 days)
Vignesh
Vignesh on 5 Feb 2024
Commented: Vignesh on 7 Feb 2024
Hi,
I am trying to plot quiver plot of 2d data and the generated quiver plot is not pointing in the direction of second dataset (x2,y2) from first dataset (x1,y1). Please let me the error I am committing in displaying the plot.
Thanks,
Vignesh
x1 = [5 5.5 6 6.5 7 7 7 6.5 6 5.5 5 5 5 ];
y1= [5 5 5 5 5 5.5 6 6 6 6 6 5.5 5];
plot (x1,y1)
hold on
xlim([-20 20])
ylim([-20 20])
x2 = [4.19 5.26 6.00 6.74 7.81 7.96 7.81 6.74 6.00 5.26 4.19 4.04 4.19];
y2 = [4.19 4.05 4.08 4.05 4.19 5.50 6.81 6.95 6.92 6.95 6.81 5.50 4.19];
plot(x2,y2)
hold on
quiver(x1,y1,x2,y2)

Accepted Answer

Cris LaPierre
Cris LaPierre on 5 Feb 2024
Your U and V values are all positive, so all quivers will point up and to the right.
I think you want U and V to be the difference between 2 and 1, and not the location of 2.
x1 = [5 5.5 6 6.5 7 7 7 6.5 6 5.5 5 5 5 ];
y1= [5 5 5 5 5 5.5 6 6 6 6 6 5.5 5];
plot (x1,y1)
hold on
x2 = [4.19 5.26 6.00 6.74 7.81 7.96 7.81 6.74 6.00 5.26 4.19 4.04 4.19];
y2 = [4.19 4.05 4.08 4.05 4.19 5.50 6.81 6.95 6.92 6.95 6.81 5.50 4.19];
plot(x2,y2)
quiver(x1, y1,x2-x1,y2-y1)
  1 Comment
Vignesh
Vignesh on 7 Feb 2024
Thanks for pointing out the reason why the vectors are not directing as expected.

Sign in to comment.

More Answers (0)

Categories

Find more on Vector Fields in Help Center and File Exchange

Tags

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!