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

2 次查看(过去 30 天)
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');

采纳的回答

Greg Dionne
Greg Dionne 2016-11-17
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 个评论
Greg Dionne
Greg Dionne 2016-11-18
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 2016-11-18
THANK YOU so much, I should've asked here from the beginning instead of straining my brain!

请先登录,再进行评论。

更多回答(1 个)

Chad Greene
Chad Greene 2016-11-17
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')

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by