Matlab - 点云数据的曲线拟合

时间:2012-02-06 01:42:29

标签: matlab stl

我有10000个(x,y)数据集,我需要拟合一条曲线。一旦我能够拟合曲线,我需要以均匀的间隔获得曲线上的点。然后我会继续修补......然后为了我的最终目标。现在我对曲线拟合感到震惊。请帮助我。

说明链接:https://docs.google.com/open?id=0BxIgxUb0m51-ZDA2ZWU0NzItM2JkZS00MWI4LTg0ZTMtNTI0ZjQzMzIxMzU3

1 个答案:

答案 0 :(得分:3)

一种方法是最小二乘曲线拟合。

您需要拟合参数化曲线[x(t), y(t)],而不是简单曲线y(x)。根据您的链接,您似乎想要拟合一条简单的曲线y(x)

MATLAB文件交换here提供了一个方便的最小二乘样条拟合工具SPLINEFIT

使用此工具,以下是如何使用最小二乘样条拟合将平滑曲线拟合到一组噪声数据的简单示例。在这种情况下,我生成了10个随机扰动的圆形数据集,然后以最小二乘方式将数字5的样条拟合到数据中。 enter image description here

function spline_test

%% generate a set of perturbed data sets for a circle
   xx = [];
   yy = [];
   tt = [];
   for iter = 1 : 10
   %% random discretisation of a circle
      nn = ceil(50 * rand(1))
   %% uniform discretisation in theta
      TT = linspace(0.0, 2.0 * pi, nn)';
   %% uniform discretisation
      rtemp = 1.0 + 0.1 * rand(1);
      xtemp = rtemp * cos(TT);
      ytemp = rtemp * sin(TT);
   %% parameterise [xtemp, ytemp] on the interval [0,2*pi]
      ttemp = TT;
   %% push onto global arrays
      xx = [xx; xtemp];
      yy = [yy; ytemp];
      tt = [tt; ttemp];    
   end

%% sample the fitted curve on the interval [0,2*pi]
   ts = linspace(0.0, 2.0 * pi, 100);

%% do the least-squares spline fit for [xx(tt), yy(tt)]
   sx = splinefit(tt, xx, 5, 'p');
   sy = splinefit(tt, yy, 5, 'p');

%% evaluate the fitted curve at ts
   xs = ppval(sx, ts);
   ys = ppval(sy, ts);

%% plot data set and curve fit
   figure; axis equal; grid on; hold on;
   plot(xx, yy, 'b.');
   plot(xs, ys, 'r-');

end      %% spline_test()

您的数据显然比这更复杂,但这可能会让您开始。

希望这有帮助。

相关问题