How can you get the x and y values from plotted points on a quiver plot?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sancheet Hoque
le 17 Nov 2016
Commenté : Sancheet Hoque
le 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 commentaires
Réponse acceptée
Greg Dionne
le 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 commentaires
Greg Dionne
le 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.
Plus de réponses (1)
Chad Greene
le 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 commentaires
Voir également
Catégories
En savoir plus sur Vector Fields dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!