フィルターのクリア

How do I fit a curve ?

1 回表示 (過去 30 日間)
SATISH SONWANE
SATISH SONWANE 2022 年 12 月 8 日
コメント済み: SATISH SONWANE 2022 年 12 月 17 日
Hi, I have been trying t fit a curve to the attached data. I tried fitPolynomialRANSAC but didn't get intended result. The data and the output are attached. Here is the code I used.
load data.mat
figure
plot(idx(:,1),idx(:,2),'*');
set(gca,'XAxisLocation','top','YAxisLocation','left','ydir','reverse');
x = idx(:,1);
y = idx(:,2);
N = 2; % second-degree polynomial
maxDistance = 5; % maximum allowed distance for a point to be inlier
[P, inlierIdx] = fitPolynomialRANSAC([x y],N,maxDistance);
yRecoveredCurve = polyval(P,x);
figure
plot(x(inlierIdx),y(inlierIdx),'.',x(~inlierIdx),y(~inlierIdx),'r+')
set(gca,'XAxisLocation','top','YAxisLocation','left','ydir','reverse');
hold on
plot(x,yRecoveredCurve,'-g','LineWidth',1)
hold off
Any help is greatly appreciated.
Edit: Requirement is that the curve should closely follow the point.
  1 件のコメント
SATISH SONWANE
SATISH SONWANE 2022 年 12 月 8 日
Tried following code too. Got a little better result.
load data.mat
x = idx(:,1);
y = idx(:,2);
p=polyfit(x,y,4);
f = polyval(p,x);
plot(x,y,'o',x,f,'-')

サインインしてコメントする。

採用された回答

Mathieu NOE
Mathieu NOE 2022 年 12 月 8 日
hello
a cardioid equation may be the solution but I have serious doubts you can fit a polynomial for this shape
as I am lazy and it's already late here , I didn't included any fitting optimisation (if that may work)
load data.mat
y = idx(:,1);
m = max(y);
y = (y-m/2)./(m/2);
x = idx(:,2);
n = max(x);
x = x./n;
% cardioid function
t = linspace(-pi,pi,100);
yc = 0.5*t .* sin( pi * .9*sin(t)./t);
xc = 0.45*abs(t) .* cos(pi * sin(t)./t);
xc = 0.05 +xc - min(xc); % shift x so that min value is zero
figure(1),plot(x,y,'r*',xc,yc,'k','linewidth',2)
  4 件のコメント
SATISH SONWANE
SATISH SONWANE 2022 年 12 月 12 日
編集済み: SATISH SONWANE 2022 年 12 月 12 日
Thank you @Image Analyst. Tried with the toolbox first and then came here. I got a new insight from @Mathieu NOE's answer though. Like for example I could fit a Sigmoid function to symmetric 'S' shaped datapoints, Gompertz function to a non-symmetrical S-shaped datapoints etc.
I will now experiment with different curve equations to get the desired shape of the curve in the toolbox. Thanks again.
Edit: Please comment if I am going in the wrong direction.
SATISH SONWANE
SATISH SONWANE 2022 年 12 月 17 日
Found this great link. Anyone who is viewing this, please check this link by @John D'Errico.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by