How to get scale and coordinates from quiver function?

Let's say I create a quiver plot with X, Y, U and V. If we think in the sense of particles, consider 'n' number of particles that particles have location [X,Y] and corresponding velocities [U, V]. The result from using 'quiver' function is, I get a vector plot that has vectors indicating direction and magnitude of particle displacement. This means that the particles have new locations [X1, Y1]. Is there a way to get this new location data?
I have checked the "get(hQ, 'Xdata')", function that gets me the original data that I have provided to the 'quiver' function, but I could not find the updated location data as inferred from the quiver plots.
I also, understand that scaling the arrows can have an impact on the new locations [X1, Y1]. But, that can not be a concern as of now. Any help is appreciated. Thanks in advance.

 採用された回答

Adam Danz
Adam Danz 2023 年 1 月 8 日
編集済み: Adam Danz 2024 年 4 月 26 日

1 投票

> the particles have new locations [X1, Y1]. Is there a way to get this new location data?
If you already have the X, Y, U and V values, then the new location is
xnew = x+u;
ynew = y+v;
However, unless scaling is turned off, the head of the quiver arrows will likely not be at [xnew, ynew] because quiver internally scales the magnitude of the arrows so they all fit nicely in the axes. Here are two solutions.
Example: turn off scaling
x = rand(1,20)*20 - 10;
y = rand(1,20)*10 + 40;
u = rand(1,20)*6 - 3;
v = rand(1,20)*10 - 5;
quiver(x,y,u,v,'off')
x1 = x + u;
y1 = y + v;
hold on
plot(x, y, 'bo') % mark arrow tail
plot(x1, y1, 'rs') % mark arrow head
Example: Use the ScaleFactor property (R024a)
Starting in R2024a, the quiver object returned by quiver contains a read-only ScaleFactor property that can be used to compute the magnitudes of the quiver arrows whether auto scaling is turned on or off. Multiply U and V by the scale factor to get the horizontal and vertical distance between the arrow tails and arrow heads.
figure()
h = quiver(x,y,u,v);
h.ScaleFactor
ans = 0.8243
x1 = x + h.ScaleFactor*u;
y1 = y + h.ScaleFactor*v;
hold on
plot(x, y, 'bo') % mark arrow tail
plot(x1, y1, 'rs')

6 件のコメント

Yuvarajendra Anjaneya Reddy
Yuvarajendra Anjaneya Reddy 2023 年 1 月 9 日
@Adam Danz Thank you for the answer. It perfectly works.
However, I do not understand the logic behind it. I consider the directional components 'U' and 'V' to be the velocities in x-direction and y-direction for a particle at location specified by the cartesian coordinates 'X' and 'Y'. They have different units, and adding them up doesn't go by rules. Would you please explain how you arrived at ''xnew = x+u; ynew = y+v;".
Adam Danz
Adam Danz 2023 年 1 月 9 日
X and Y are initial position values some Cartesian coordinate system.
U and V and the horizontal and vertical velocity components within that system. They are Δx Δy and represent a displacement across some duration. The resultant endpoint of (X,Y) after it is moved is the vector sum of the horizontal and vertical components.
This is also mentioned in the quiver documentation, "...the first arrow originates from the point X(1) and Y(1), extends horizontally according to U(1), and extends vertically according to V(1)".
Yuvarajendra Anjaneya Reddy
Yuvarajendra Anjaneya Reddy 2023 年 1 月 9 日
Thanks for replying. The above case is valid when the time duration is 1 sec or a unit value.
i.e, u = (x1 - x)/(dt). If dt is 1, then upon rearranging, x1 = (u + x). This clears my doubts. :)
Adam Danz
Adam Danz 2023 年 1 月 9 日
In quiver(x,y,u,v), u and v are the horizontal and vertical components of the vector that starts at (x,y). You can use any units for u and v as long as they are consistent between u and v. For example, u and v could represent pressure or miles-per-3-hours instead of mph. Your choice of units affects how you interpret the magnitude (or length) of the resultant vector which shares the same units as U and V.
Yuvarajendra Anjaneya Reddy
Yuvarajendra Anjaneya Reddy 2023 年 1 月 10 日
@Adam Danz Thank you.. It is much clear now..
Adam Danz
Adam Danz 2024 年 4 月 26 日
I've updated my answer to include a new solution available in R2024a using the ScaleFactor property.

サインインしてコメントする。

その他の回答 (1 件)

MJFcoNaN
MJFcoNaN 2023 年 1 月 8 日

1 投票

Hello,
The vector field is instantaneous, therefore, you have to provide the increment of time for getting a new proximate location. Or you can calculate it from a time series of vector fields.

1 件のコメント

Yuvarajendra Anjaneya Reddy
Yuvarajendra Anjaneya Reddy 2023 年 1 月 8 日
@MJFcoNaN Thank you for your answer. Involving time variable can get tricky and complex in the code I'm using, anyways I appreciate the valid comment.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeVector Fields についてさらに検索

製品

リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by