How can i set the dimension of the arrow in a quiver plot?

155 ビュー (過去 30 日間)
michele modina
michele modina 2022 年 11 月 14 日
編集済み: Adam Danz 2024 年 4 月 26 日
I want to set the arrows dimensions in my quiver plot to a fixed value. I've used this function
but this dosent permit to scale the vectors. So using this i solve the problem of the arrow but i cant scale my vectors.
Thanks!

回答 (2 件)

Aritra
Aritra 2022 年 11 月 23 日
Hi Michele,
As per my understanding you are facing some issue while scaling the vectors in your quiver plot. To perform vector scaling, you can take help of the scale parameter in quiver(___,scale) function. The arrow scaling factor is specified as a positive number or ‘off’. When the AutoScale’ property of the quiver object is set to off such as quiver(X,Y,U,V,'off')’, the length of the arrow is entirely determined by U and V.
For more details, please see this MathWorks documentation below for more information on 3-D quiver: https://in.mathworks.com/help/matlab/ref/quiver3.html

Adam Danz
Adam Danz 2024 年 4 月 26 日
編集済み: Adam Danz 2024 年 4 月 26 日
Understanding quiver auto scaling
When using quiver(X,Y,U,V,__), U and V are the horizontal and vertical vector magnitudes. However, the magnitude of the quiver arrows that represent the U,V vectors are scaled to fit nicely in the axes. Quiver's AutoScale property can be used to turn auto scaling on or off. When auto scaling is off, the magnitudes of the quiver arrows are solely based on the U and V inputs. For example, you can visually confirm that two quiver arrows below have the expected magnitudes of 1 and 3 units.
h = quiver([0 2],[0 0],[0 0],[1,3],'off');
h.AutoScale
ans =
OnOffSwitchState enumeration off
grid on
When auto scaling is on, the magnitude of the arrows is relative to the U and V inputs but U and V do not always directly determine the arrow magnitudes. In this next example, you can visually confirm that the two quiver arrows do not have magnitudes of 1 and 5 units.
figure()
h = quiver([0 2],[0 0],[0 0],[1,5]);
h.AutoScale
ans =
OnOffSwitchState enumeration on
grid on
Controlling quiver arrow scale: 3 solutions
1. Turn off auto scaling
As the first example above show, turning off auto scaling will force the quiver arrows to use U and V to determine the arrow magnitudes. There are two ways to turn off auto scaling.
  • quiver(___,scale) where scale can be 0 or 'off'.
  • h = quiver(__); h.AutoScale = 'off';
2. Scale U and V inputs (and turn off auto scaling)
Sometimes simply turning off auto scaling won't due, particularly when there is a large range of magnitudes. In that case, you may want more control over the arrow magnitudes. In that case you can directly scale the U and V values before providing them as inputs to quiver. You'll still need to turn off auto scaling but this time, the arrow magnitudes will be scaled to your preferences.
scale = 0.2;
Usc = scale*U;
Vsc = scale*V;
quiver(X,Y,Usc,Vsc,'off')
3. Adjust auto scaling
Finally, if the goal is to adjust the magnitudes of the auto-scaled quiver arrows, leave AutoScale on and set the AutoScaleFactor propery. The AutoScaleFactor value is like a smudge factor. A value of 1 means that arrows are scaled to the full axes size. Values less than one will decrease the arrow magnitudes and values greater than 1 will increase the arrow magnitudes. There are two ways to set the AutoScaleFactor.
  • quiver(___,scale) where scale is a numeric scalar
  • h = quiver(__); h.AutoScaleFactor = ___;
Quiver's ScaleFactor propery
In R2024a we added the read-only ScaleFactor property that returns the scaling used to determine the arrow magnitudes based on U, V, and AutoScaleFactor when AutoScale is on. This property is helpful when you need to know the final scale factor that quiver used to scale your data. One common use is to compute the coordinate of the arrow heads.
x = zeros(1,10);
y = zeros(1,10);
th = linspace(-pi,pi,10);
u = sin(th);
v = cos(th);
figure()
h = quiver(x,y,u,v);
h.ScaleFactor
ans = 0.9000
x1 = x + h.ScaleFactor*u;
y1 = y + h.ScaleFactor*v;
hold on
plot(x1,y1,'ro','MarkerSize', 12)
axis equal padded

カテゴリ

Help Center および File ExchangeVector Fields についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by