2015-09-07 53 views
1

我需要绘制一小块与其平衡态有小偏差的点。使用quiver它应该是这样的:仅绘制颤抖的终点

enter image description here

现在我要绘制只是位于箭头提示标志。怎么做?

输入数据是U和V的偏差(关于笛卡尔轴),得到了X,Y矢量起点的坐标是没有问题的。

+2

如果你知道X,点Y的起源和U,V偏差,那么你知道终点,不要你呢?然后使用'plot(x,y,'。'')来绘制它们' –

+0

@AnderBiguri但是'颤抖'对这些'U','V'应用了一个比例尺。你必须包含那个尺度,这个尺度并不是先验知识 –

+0

@LuisMendo,但是颤抖有一个“尺度”输入选项! –

回答

3

你不能简单地使用像plot(X+U, Y+V, 'o')因为quiver适用的自动计算规模UV让所有的箭适合很好的身影。您需要包含该比例。

展望quiver的代码复制,计算的是大规模的一部分,你可以进行如下操作:

%// Example data 
x = rand(1,20); 
y = rand(1,20); 
u = rand(1,20); 
v = rand(1,20); 

%// Taken from "quiver.m". Computes autoscale 
if min(size(x))==1, n=sqrt(numel(x)); m=n; else [m,n]=size(x); end 
delx = diff([min(x(:)) max(x(:))])/n; 
dely = diff([min(y(:)) max(y(:))])/m; 
del = delx.^2 + dely.^2; 
if del>0 
    len = sqrt((u.^2 + v.^2)/del); 
    maxlen = max(len(:)); 
else 
    maxlen = 0; 
end 
if maxlen>0 
    autoscale = 0.9/maxlen; 
else 
    autoscale = 0.9; 
end 

%// quiver plot 
quiver(x, y, u, v) 
hold on 

%// plot marker at arrow tips, including computed autoscale 
plot(x+autoscale*u, y+autoscale*v, 'o') 

如果指定比例参数quiver,这样的说法是一个因素相乘内部计算的比例。所以,你必须包括在plot还有:

%// quiver plot including manual scale factor 
quiver(x, y, u, v, .5) 
hold on 

%// plot marker at arrow tips, including computed autoscale and manual scale 
plot(x+.5*autoscale*u, y+.5*autoscale*v, 'o') 

enter image description here

+0

不错!如果我有Matlab,我会抢劫你这个答案:P Good one –

+0

@AnderBiguri谢谢:-) –