Plotting just the endpoint of quiver
Asked Answered
F

1

1

I need to plot a block of points with small deviations from their equilibrium states. Using quiver it would look like this:

enter image description here

And now I want to plot just markers located on the arrow tips. How to do that?

Input data are U and V deviations (on cartesian axes), getting the X,Y coordinates of vector origins is not a problem.

Formative answered 7/9, 2015 at 10:32 Comment(6)
If you know the X, Y origins of the point and the U, V deviations, then you know the endpoints, dont you? Then just plot them using plot(x,y,'.')Gond
@AnderBiguri But quiver applies a scale to those U, V. You'd have to include that scale, which is not known a prioriComb
@LuisMendo well, but quiver has a scale input option!Gond
@AnderBiguri But that scale only multiplies the internally computed scale. Try itComb
@LuisMendo Cant at the moment. Hummm, then I guess there are only 2 options: 1) reverse engineer the internal scale (maybe edit quiver ?) 2)plot the arrows with something else. There are several FEX submissions. Dont have Matlab at the moment to play with it unfortunately.Gond
@Ander I followed the edit quiver route! :-DComb
C
3

You can't simply use something like plot(X+U, Y+V, 'o') because quiver applies an automatically computed scale to U and V so that all arrows fit nicely in the figure. You need to include that scale.

Looking into quiver's code and replicating the part that computes that scale, you can proceed as follows:

%// Example data
x = rand(1,20);
y = rand(1,20);
u = rand(1,20);
v = rand(1,20);

%// Taken from "quiver.m". Computes autoscale
if min(size(x))==1, n=sqrt(numel(x)); m=n; else [m,n]=size(x); end
delx = diff([min(x(:)) max(x(:))])/n;
dely = diff([min(y(:)) max(y(:))])/m;
del = delx.^2 + dely.^2;
if del>0
    len = sqrt((u.^2 + v.^2)/del);
    maxlen = max(len(:));
else
    maxlen = 0;
end
if maxlen>0
    autoscale = 0.9 / maxlen;
else
    autoscale = 0.9;
end

%// quiver plot
quiver(x, y, u, v)
hold on

%// plot marker at arrow tips, including computed autoscale
plot(x+autoscale*u, y+autoscale*v, 'o')

If you specify a scale argument to quiver, that argument is a factor that multiplies the internally computed scale. So you have to include that in plot as well:

%// quiver plot including manual scale factor
quiver(x, y, u, v, .5)
hold on

%// plot marker at arrow tips, including computed autoscale and manual scale
plot(x+.5*autoscale*u, y+.5*autoscale*v, 'o')

enter image description here

Comb answered 7/9, 2015 at 12:49 Comment(2)
Nice! I would have robbed you this answer if I had Matlab :P Good oneGond
@AnderBiguri Thanks :-)Comb

© 2022 - 2024 — McMap. All rights reserved.