1

I am trying to understand the quiver function, moreover, what exactly specifies the quiver's origin, direction, and length. I understand it is different from plotv.

For instance, the code quiver(0,1); axis equal produces:

first example

which seems to start at [1,1], and end at [1,2] for a length of 2. I'm not too sure how MATLAB worked that out?

Secondly, if I provide a vector if inputs such as quiver([0 0 0 0],[1 2 3 4]), I obtain:

second example

So each one seems to start at an integer value, but again I'm not sure how MATLAB is deducing the length or direction?

Lastly, I was trying to plot a sine wave with quivers starting at the origin and ending at the value of the sine wave on the y-axis. This is how far I got:

x = linspace(0,2*pi,100);
y = sin(x);
h = quiver(x(1:3:end),y(1:3:end));

example 3

Why do the quivers angle forward? And how can I normalize the arrow heads so they are the same size? I tried accessing the property MaxHeadSize, but it only works for the largest one.

Could someone please describe what is going on?

tdy
  • 36,675
  • 19
  • 86
  • 83
Steve Hatcher
  • 715
  • 11
  • 27
  • 1
    Did you read [the documentation to `quiver`](https://www.mathworks.com/help/matlab/ref/quiver.html)? It’s quite clear and has lots of examples. Simply type `doc quiver` in MATLAB! – Cris Luengo Jul 05 '20 at 13:56
  • 1
    Hello, yes I did have a read but could still not figure out my simple examples. The `x,y,u,v` inputs were puzzling me. Thanks. – Steve Hatcher Jul 06 '20 at 04:54

1 Answers1

3

Ans 1: From Matlab's quiver documentation, quiver accepts either x, y, u, v or u, v. You seem to be using the later case, ie, providing just the vector's lengths in the x and y direction. In such a case, Matlab does the quiver plot at equally spaced points in the xy plane which happens to start from (1,1). If you do not want this, consider providing x and y data as well to the quiver function, ie, quiver( 0, 0, 0, 1 ).

Ans 2: Direction and length of the vectors are being provided by you. Lengths of the vectors in the plot are being scaled though [Ref: quiver properties]. If you do not want this, use 'AutoScale', 'off' with the quiver function, ie,

quiver( [0, 0, 0, 0], [1, 2, 3, 4], 'AutoScale', 'off' )

Ans 3: Vectors in the sine graph lean forward because you have provided a non-zero x component to the vectors in your quiver command. Try this instead

x = linspace( 0, 2*pi, 20 );    % x-coordinates of the vectors' origin.
y = zeros( size( x ) );         % y-coordinates of the vectors' origin.
u = zeros( size( x ) );         % x-components of the vectors.
v = sin( x );                   % y-components of the vectors.

h = quiver( x, y, u, v, 'AutoScale', 'off' );

Ans 4: Sadly there is no such option to have quiver arrow heads of the same size. All you can do is modify the 'MaxHeadSize' option to suit your needs. (See the quiver properties reference for more info on this.) Other than this, I found this answer which obtains the desired effect using annotations.

Ombrophile
  • 613
  • 1
  • 7
  • 13
  • Thanks a lot for the answer, I couldn't get my head around the documentation. I will need to play around with your solution in Ans 3 to figure out how it works. – Steve Hatcher Jul 05 '20 at 10:06
  • 1
    You are welcome. I have modified the code in ans 3 a little bit. Hope it is clearer now. – Ombrophile Jul 05 '20 at 11:18