简体   繁体   中英

Fitting a curve using matlab

I have a plot with two intersecting parabolas. Is there a way that I can detect the two correctly and fit two parabolas, one through each of them? My current code fits only a single parabola:

x=-100:1:100;
y=(x.^2)/(4);
x1=-50:1:150;
y1=(x.^2)/(4);
x=[x,x1];
y=[y,y1];
f = fittype('((x)*(x))/4*p',...
'dependent',{'y'},'independent',{'x'},...
'coefficients',{'p'})
fit1= fit(x',y',f)
plot(fit1,x,y)

在此处输入图片说明

Following the suggestions I was able to write a code that runs ransac for curves

function [f1] = Ransac(x,y)
voting=[0,0,0,0];
for i=1:10000

[y1,idx] = datasample(y,5);
x1=x(idx);
p = polyfit(x1,y1,2);
f1 = polyval(p,x);
error=(((f1-y).^2));
error(error>100)=0;
indx =find(ismember(voting(:,1:3),'rows'),1);
if (isempty(indx)==1)
    voting=[voting;[p,sum(error)]];
else
    voting(indx,4) =   voting(indx,4)+sum(error);
end
end
[s,t]=max(voting(:,4));
p=voting(t,1:3);
f1 = polyval(p,x);
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM