New to matlab, quick question about quiver

18 views (last 30 days)
C G
C G on 21 Jan 2016
Answered: Walter Roberson on 21 Jan 2016
I'm trying to plot a simple vector field but I'm unsure of the syntax for quiver because it doesn't seem to be working. It's just displaying an empty plot
% code
v = -5:0.1:5;
[x,y] = meshgrid(v);
u1=(2./x);
u2=(2.*y./(x.^2));
quiver(x,y,u1,u2)

Answers (2)

Star Strider
Star Strider on 21 Jan 2016
They plot, but you have to turn off the scaling to see them. I’ll let you ponder how best to set their lengths, and perhaps set the axis limits as well. (You may have to narrow them significantly.)
To turn off scaling, set the scaling parameter to 0:
quiver(x,y,u1,u2,0)
  1 Comment
Kirby Fears
Kirby Fears on 21 Jan 2016
Read the quiver() documentation for more info. Here's the section regarding the scale argument.
quiver(...,scale) automatically scales the arrows to fit within the grid and then stretches them by the factor scale. scale = 2 doubles their relative length, and scale = 0.5 halves the length. Use scale = 0 to plot the velocity vectors without automatic scaling. You can also tune the length of arrows after they have been drawn by choosing the Plot Edit tool, selecting the quiver object, opening the Property Editor, and adjusting the Length slider.

Sign in to comment.


Walter Roberson
Walter Roberson on 21 Jan 2016
For me it shows a bunch of dots.
You have a scaling problem. Due to division by 0 your u1 runs from -20 to +infinity and your u2 runs from -infinity to +infinity.
You can get a slightly better plot if you use
u1(~isfinite(u1)) = nan;
u2(~isfinite(u2)) = nan;
and you can do even better if you confine u1 and u2 to smaller ranges, such as
u2 = min(max(u2,-20),20);
and just expand the size of your plot by dragging a corner of your figure to resize it.

Categories

Find more on Vector Fields in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!