I have data points represented by red stars on a graph (Fig 1, attached), and I would like to fit a curve to them. The curve does not have to be accurate -- it just needs to serve as a visual guide. I have drawn a sketch below to show what I would like. The other curves on the graph are by-products from the code I pulled this image from, and are not relevant to this problem. How can I fit a curve to the red data points in MATLAB?
I have tried using polyfit, smoothingspline, pchip and other curve-fitting tools, but all of them connect the wrong data points together, since this graph is actually x = f(y). In MS Excel, if I switch the axes so the curve becomes a one-to-one function where y = f(x), I can easily fit a quadratic curve to the points.
I am currently plotting each point indivdually. I can plot the points with a line, but it is not very smooth (see Fig 2, attached). I guess I could just increase the number of data points, but that increases computation time too much. Any suggestions?
Please find below some things I have already tried. The red data points are saved in 1 x 11 doubles p_tn (x values) and p_Tn (y values).
Thank you so much! PLEASE let me know if you need more information, clarification, or data.
[p,s,mu] = polyfit(p_Tn,p_tn,3);
[Y,delta] = polyval(p,p_Tn,s,mu)
X = linspace(0,0.05,length(Y));
xq = linspace(0,0.05,100);
p = pchip(p_tn',p_Tn',xq);
pp = ppval(p,xq);
f = fit(p_tn',p_Tn','smoothingspline');
for i = 1:length(p_tn)-1
if p_tn(i) > p_tn(i+1)
x1(i) = p_tn(i) ;
y1(i) = p_Tn(i) ;
elseif p_tn(i) < p_tn(i+1)
x2(i) = p_tn(i) ;
y2(i) = p_Tn(i) ;
p1 = polyfit(x1,y1,2);
p2 = polyfit(x2,y2,2);
xf1 = linspace(min(x1),0.05);
xf2 = linspace(min(x2),0.05);
f1 = polyval(p1,xf1);
f2 = polyval(p2,xf2);