How to get scale and coordinates from quiver function?

10 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Adam Danz
Adam Danz el 8 de En. de 2023
Editada: Adam Danz el 26 de Abr. de 2024
> 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 comentarios
Yuvarajendra Anjaneya Reddy
Yuvarajendra Anjaneya Reddy el 10 de En. de 2023
@Adam Danz Thank you.. It is much clear now..
Adam Danz
Adam Danz el 26 de Abr. de 2024
I've updated my answer to include a new solution available in R2024a using the ScaleFactor property.

Iniciar sesión para comentar.

Más respuestas (1)

MJFcoNaN
MJFcoNaN el 8 de En. de 2023
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 comentario
Yuvarajendra Anjaneya Reddy
Yuvarajendra Anjaneya Reddy el 8 de En. de 2023
@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.

Iniciar sesión para comentar.

Categorías

Más información sobre Vector Fields en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by