插值x向量

时间:2016-05-23 20:41:21

标签: matlab interpolation

我正在使用interp1函数在此图表上插入一些点

enter image description here

我的问题是我希望新点是等距的。但是在interp1函数中,输入参数是x(before)y(before)x(new),它是垂直坐标而不是轮廓距离。

我的问题是,是否还有其他功能可以解决我的问题?如果没有,是否有人知道如何转换x-vector?

编辑:

我的问题的例子在这里:

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;

1 个答案:

答案 0 :(得分: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