1

I am simulating the motion of particles in MATLAB. I am using quiver to be able to get the direction of their motion. However, I would like to have only the arrowhead without the stem. I am unable to achieve this.

I tried using the following,

quiver(x,y,vx,vy,'LineStyle','none','ShowArrowHead','on')

to get rid of the stem, but the arrowhead too does not show up. Is there a way around this?

2 Answers 2

2

'LineStyle','none' didn't work because the style applies both to the stem and to the head, so setting it to none hides both.

This can be solved by digging around some undocumented properties of the Quiver object. Exploring the properties of a Quiver object (using struct(<handle to quiver plot>)) we can see that a quiver plot has NodeChildren property, and that it is made of 4 elements,

>> hq = quiver(x,y,u,v);
>> hq.NodeChildren
ans = 
  4×1 graphics array:

  ListOfPointsHighlight
  LineStrip
  LineStrip
  Marker

The LineStrip objects you see above, correspond, from top to bottom, to tails and the heads. From here it's just a matter of hiding the tails via their Visible property:

[x,y] = meshgrid(0:0.2:2,0:0.2:2);
u = cos(x).*y;
v = sin(x).*y;

figure();
hq = quiver(x,y,u,v);

pause(0.1); % this appears to help
hq.NodeChildren(2).Visible = 'off';

Resulting in:

enter image description here

Tested on R2019a.

0

In this case, quiver will plot the arrows offset from the datapoints, where they would normally occur on the end of the arrow stem. It is difficult to control the stem-length to the head size, plot closed arrowheads, or modify the shape and location of the quiver arrows using MATLAB's quiver() command.

An alternative is the file-exchange arrow3() function, which is available here:

https://www.mathworks.com/matlabcentral/fileexchange/14056-arrow3

The arrow3() function has many examples here:

https://kr.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/14056/versions/16/previews/arrow3_examples.html

An example using the code for the quiver() function with arrow3() instead

[x,y] = meshgrid(0:0.2:2,0:0.2:2);
u = cos(x).*y;
v = sin(x).*y;

figure();
%hq = quiver(x,y,u,v);
p1 = [x(:) y(:)]; % data start point
u = u(:); v=v(:);
arrow3(p1,p1+0.01*[u,v],'k',1,2); % create small (0.01) arrow stems

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.