使用 matlab 拟合曲线

Fitting a curve using matlab

我有一个带有两条相交抛物线的图。有没有一种方法可以让我正确地检测到这两个并拟合两个抛物线,一个通过它们中的每一个?我当前的代码只适合一个抛物线:

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)

按照建议,我能够编写一个运行 ransac 曲线的代码

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