2016-05-23 51 views
0

我使用的interp1的函數,在該圖插值幾點插值X-矢量

enter image description here

我的問題是,我想新的點是等距。但在interp1函數中,輸入參數是x(before),y(before)x(new),它是垂直座標而不是輪廓距離。

我的問題是如果有任何其他功能解決我的問題?如果沒有,有誰知道我該如何轉換x向量?

編輯:

與我的問題的例子是在這裏:

x=0:0.1:10; 
y=x.^4; 

xx=linspace(min(x),max(x),10); 
yy=interp1(x,y,xx); 

hold on; 
plot(x,y); 
plot(xx,yy); 
plot(xx,yy,'ro'); 
hold off; 
+0

是,該行表示正齒輪的腳和點創建網格的第一步。 – Antreas

+0

如果你有曲線的方程,我認爲這可以作爲[微分變化](https://en.wikipedia.org/wiki/Calculus_of_variations)問題來解決。在數值上,這可以解決作爲一個等距分佈問題(見我的答案[這裏](http://scicomp.stackexchange.com/a/21849/17671))採取網格密度ρ(x)= sqrt(1+( u_x)^ 2)',其中'u_x'是曲線的一階導數。 – Steve

回答

1

您可以通過重新制定你的曲線的length along the curve參數函數做到這一點。你想要的是最終點(你插入的地方)在它們之間具有相等的長度。可以通過將「真」曲線近似爲連接原始數據點的分段線性曲線來做到這一點。

假設我們有在基質xy,其中每行是一個點,在x/y座標是在1/2列的一些數據點:

% make some fake data 
% triple exponential function has nonuniform spacing 
x = linspace(.4, .8, 20)'; 
y = exp(exp(exp(x))); 
x = (x - min(x)) ./ range(x); 
y = (y-min(y)) ./ range(y); 
xy = [x, y]; 

找到每個點的長度沿曲線,在第一點從0開始:

% distance of each point from previous point 
% note that points need to be in order 
ds = [0; sqrt(sum(diff(xy, 1, 1) .^ 2, 2))]; 

% integrate to find length along the curve 
s = cumsum(ds); 

現在,同時考慮xy是的s功能。內插xy在沿着曲線的一組等間距的長度:

% find a set of equally spaced lengths along the curve 
si = linspace(s(1), s(end), 20)'; 

% interpolate x and y at these points 
xyi = interp1(s, xy, si); 

驗證解決方案的工作:

% distance between successive interpolated points 
% they should all be equal 
sqrt(sum(diff(xyi, 1, 1) .^ 2, 2) 

原始數據:

enter image description here

插值:

enter image description here