颤抖不绘制箭头只是很多的蓝色,matlab [英] quiver not drawing arrows just lots of blue, matlab

查看:103
本文介绍了颤抖不绘制箭头只是很多的蓝色,matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我没有真正得到箭头时,有人可以告诉我颤抖绘图功能在做什么,它只是在空白处填充了很多蓝色,请看下面的图片,然后看一下我的代码.

Can somebody tell me what I am doing wrong with the quiver plotting function when I don't really get arrows, it just fills the empty space with lots of blue.Look at the image below and then look at my code.

这只是我轮廓的一部分,因为如果我尝试将其放大,则会消耗处理能力.但是我的功能,轮廓和其他所有功能都起作用,这只是我遇到麻烦的颤栗.

This is just a part of my contour since this eats up proccessing power if I try to draw it larger. But my function, the contours and everything else works, it's just the quiver I'm having trouble with.

interval = -100:100;

[X Y] = meshgrid(interval, interval);

h = figure;
contour(X, Y, Z);

hold on;

[FX,FY] = gradient(-Z);
quiver(X, Y, FX, FY);

hold off;

如果我使矩阵更稀疏,例如与间隔= linspace(-800,1600,1200);"结果将如下所示:

If I make my matrix more sparse, e.g. with "interval = linspace(-800, 1600, 1200);" the result will look like this:

我需要的是这样的轮廓线,但是箭头应该随它们一起流动.现在,即使我进一步放大,它们也看起来像点.如果我缩小,整个窗口将变成蓝色.

What I need are contour lines like that, but the arrows should flow with them. Right now these just look like dots, even if I zoom in further. If I zoom out the entire window will be blue.

如果有人想使用它来解决这个问题,这里是完整的脚本.

Here is the script in its entirety if anyone wants to play with it to figure this out.

m1 = 1;
m2 = 0.4;
r1 = [1167 0 0];
r2 = [-467 0 0];
G = 9.82;

w = sqrt( G*(m1+m2) / norm(r1-r2)^3 );

interval = linspace(-800, 1600, 1200);

% Element-wise 2-norm
ewnorm = @(x,y) ( x.^2 + y.^2 ).^(1/2);

% Element-wise cross squared
ewcross2 = @(w,x,y) w^2.*( x.*x + y.*y );

[X Y] = meshgrid(interval, interval);

Z = - G*m1 ./ ewnorm( X-r1(1), Y-r1(2) ) - G*m2 ./ ewnorm( X-r2(1), Y-r2(2) ) - 1/2*ewcross2(w,X,Y);

h = figure;
contour(Z);

daspect([1 1 1]);

saveas(h, 'star1', 'eps');

hold on;

[FX,FY] = gradient(-Z);
quiver(X, Y, FX,FY);

hold off;

推荐答案

问题是网格过于密集.您只需要具有尽可能少的元素即可生成有用的网格.因此,请尝试降低网格的密度:

The problem is that the mesh is too dense. You only want to have as few elements as necessary to generate a useful mesh. As such, try reducing the density of the mesh:

interval = -100:2:100

如果要经常更改限制,则可能要避免使用X:Y:Z公式.请使用 linspace 函数:

If you're going to be changing the limits often, you probably want to avoid using the X:Y:Z formulation. Use the linspace function instead:

interval = linspace(-100,100,10);

这将确保无论您有什么限制,您的网格都将为10x10.在下面的评论中,您提到当您使用非常大的网格时,箭头显示为点.这是预料之中的.箭头反映了给定点的速度".当您的图被很大程度地放大时,图上任何给定点的速度将几乎为0,因此箭头非常小.查看 quiver绘图文档,以及 quivergroup属性,以了解更多详细信息.

This will ensure that no matter what your limits, your mesh will be 10x10. In the comment below, you mention that the arrows are appearing as dots when you use a very large mesh. This is to be expected. The arrows reflect "velocity" at a given point. When your plot is scaled out to a very large degree, then the velocity at any given point on the plot will be almost 0, hence the very small arrows. Check out the quiver plot documentation, as well as the quivergroup properties, to see more details.

如果绝对必须看到较大的箭头,则可以尝试将AutoScale属性设置为off,或增大AutoScaleFactor:

If you absolutely must see arrows at a large scale, you can try setting the AutoScale property to off, or increasing the AutoScaleFactor:

quiver(X, Y, FX, FY, 'AutoScale', 'off');
quiver(X, Y, FX, FY, 'AutoScaleFactor', 10);

您可能还想使用MarkerSizeMaxHeadSize属性.我真的只是建议查看所有QuiverGroup属性并尝试一下.

You may also want to play with the MarkerSize and MaxHeadSize properties. I really just suggest looking at all the QuiverGroup properties and trying things out.

这篇关于颤抖不绘制箭头只是很多的蓝色,matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆