2012-02-06 328 views
3

我有10000個數據集(x,y),我需要擬合曲線。一旦我能夠擬合一條曲線,我需要以均勻的間隔得到曲線上的點。然後,我會繼續修補......然後爲了達到我的最終目標。現在我對曲線擬合感到震驚。請幫助我。Matlab - 點雲數據的曲線擬合

鏈接的描述:https://docs.google.com/open?id=0BxIgxUb0m51-ZDA2ZWU0NzItM2JkZS00MWI4LTg0ZTMtNTI0ZjQzMzIxMzU3

+0

當STL是C++特有的時候,是否有這個標籤爲STL的原因? – templatetypedef 2012-02-06 04:44:23

+0

@templatetypedef:我假設他們是指'* .stl'文件類型 - 用於三角化表面的簡單幾何文件格式:http://en.wikipedia.org/wiki/STL_%28file_format%29 – 2012-02-06 04:52:44

回答

3

一種方法是最小二乘曲線擬合。

您需要擬合參數化曲線[x(t), y(t)],而不是簡單的曲線y(x)。根據你的鏈接,它看起來像你試圖適合一個簡單的曲線y(x)

有一個方便的最小二乘樣條擬合工具SPLINEFIT可從MATLAB文件交換here可用。

使用此工具,下面是一個簡單示例,說明如何使用最小二乘樣條擬合將光滑曲線擬合到一組噪聲數據。在這種情況下,我生成了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() 

你的數據顯然比這更復雜,但這可能會讓你開始。

希望這會有所幫助。