[英]Matlab curve fitting a set of 2D points
Currently I have a set of 2D points as shown below. 目前我有一组2D点,如下所示。
I need to obtain fitted curve of the points to determine the shape of the object. 我需要获得点的拟合曲线以确定物体的形状。
Matlab offers a spline fitting function . Matlab提供样条拟合功能 。 I have to applied it to the set of points.
我必须将它应用于一组点。 However, the results I am obtaining is shown below.
但是,我得到的结果如下所示。
.
。
xx = linspace(-10,10,20);
pp2 = splinefit(PV(:,1),PV(:,2),8,5);
y2 = ppval(pp2,xx);
plot(x,y,'.',xx,y2), grid on
axis([-10 10 -10 10]);
PV is the data points. PV是数据点。 I am unsure where the problem lies.
我不确定问题出在哪里。
You are trying to fit PV(:,1) = f( PV(:,2) )
that is, fitting directly y=f(x)
. 你试图拟合
PV(:,1) = f( PV(:,2) )
,即直接拟合y=f(x)
。 But as you can see from your points, there are multiple values of y
for certain values of x
(around x=0
and x=-15
). 但是从你的观点可以看出,对于某些
x
值( x=0
和x=-15
), y
有多个y
值。 Thus, you cannot mathematically fit y=f(x)
for any function f(.)
here. 因此,您无法在数学上将
y=f(x)
拟合为此处的任何函数f(.)
。
What you can do is fit a parametric curve using an auxiliary parameter t
: 您可以做的是使用辅助参数
t
拟合参数曲线:
t = linspace(0, 1, size(PV,1));
ppx = splinefit(PV(:,1),t,8,5); % x = f_x(t)
ppy = splinefit(PV(:,2),t,8,5); % y = f_y(t)
Now you can plot the curve (f_x(t), f_y(t))
: 现在您可以绘制曲线
(f_x(t), f_y(t))
:
tt = linspace(0, 1, 50);
x2 = ppval(ppx, tt);
y2 = ppval(ppy, tt);
plot( PV(:,1), PV(:,2), '.', x2, y2); grid on;
axis([-10 10 -10 10]);
Note : 注意 :
This fitting scheme is based on the assumption that the points in PV
are ordered : That is, the curve should follow from PV(1,:)
to PV(2,:)
and then to PV(3,:)
and so on. 该拟合方案基于
PV
中的点是有序的假设:即,曲线应该从PV(1,:)
到PV(2,:)
然后到PV(3,:)
等等。 If this is not the case (eg, PV(1,:)
has x value of ~-10, PV(2,:)
has x value of ~0 and PV(3,:)
jumps back to x ~-10) then you are in deep s&#t. 如果不是这种情况(例如,
PV(1,:)
x值为〜-10,则PV(2,:)
x值为~0且PV(3,:)
跳回x~-10)然后你就陷入了困境。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.