How can you get the x and y values from plotted points on a quiver plot?
2 views (last 30 days)
Show older comments
Sancheet Hoque
on 17 Nov 2016
Commented: Sancheet Hoque
on 18 Nov 2016
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');
0 Comments
Accepted Answer
Greg Dionne
on 17 Nov 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 Comments
Greg Dionne
on 18 Nov 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.
More Answers (1)
Chad Greene
on 17 Nov 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')
0 Comments
See Also
Categories
Find more on Vector Fields in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!