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

2 ビュー (過去 30 日間)
Sancheet Hoque
Sancheet Hoque 2016 年 11 月 17 日
コメント済み: Sancheet Hoque 2016 年 11 月 18 日
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 Center および File ExchangeVector Fields についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by