How can you get the x and y values from plotted points on a quiver plot?

2 visualizaciones (últimos 30 días)
I have quiver plots in which I used longitude and latitude for x and y and vectors that are u and v. I was wondering if there is anyway to extract all of these points in Matlab. I know code below gives me a range, but I want the specific x and y values and the corresponding u and v. I want these values so I can compare and receive more information from another data set
xLimits = get(gca,'Xlim');
yLimits = get(gca,'Ylim');

Respuesta aceptada

Greg Dionne
Greg Dionne el 17 de Nov. de 2016
You'll want to get the line handle.
Something like:
>> hq = quiver([1 2 3],[3 1 2],[4 1 5],[2 1 2])
hq =
Quiver with properties:
Color: [0 0.4470 0.7410]
LineStyle: '-'
LineWidth: 0.5000
XData: [1 2 3]
YData: [3 1 2]
ZData: []
UData: [4 1 5]
VData: [2 1 2]
WData: []
Once you have the handle, you can reference the properties either via "get" or direct property access:
>> get(hq, 'XData')
ans =
1 2 3
In more recent versions of MATLAB you can use direct property access:
>> hq.XData
ans =
1 2 3
Don't have the handle? You can search for it:
>> hq = findobj(gca,'Type','quiver')
hq =
Quiver with properties:
Color: [0 0.4470 0.7410]
LineStyle: '-'
LineWidth: 0.5000
XData: [1 2 3]
YData: [3 1 2]
ZData: []
UData: [4 1 5]
VData: [2 1 2]
WData: []
  3 comentarios
Greg Dionne
Greg Dionne el 18 de Nov. de 2016
If you want to find all the values that aren't NaN, you can do something like:
x = hq.XData;
y = hq.YData;
u = hq.UData;
v = hq.VData;
% get rid of any nan
idxgood = ~(isnan(x) | isnan(y) | isnan(u) | isnan(v));
x = x(idxgood);
y = y(idxgood);
u = u(idxgood);
v = v(idxgood);
Not sure if that's what you meant, but give it a whirl and let us know.
Sancheet Hoque
Sancheet Hoque el 18 de Nov. de 2016
THANK YOU so much, I should've asked here from the beginning instead of straining my brain!

Iniciar sesión para comentar.

Más respuestas (1)

Chad Greene
Chad Greene el 17 de Nov. de 2016
If you can get a handle from when the quiver plot was created, it's easy:
[x,y] = meshgrid(0:0.2:2,0:0.2:2);
u = cos(x).*y;
v = sin(x).*y;
h = quiver(x,y,u,v);
then the x data can be obtained by
X = get(h,'Xdata');
and the y data is obtained by the same method. If you don't already have a handle for the quiver plot, you can try to find it by
get(gca,'Children')

Categorías

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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by