MATLAB: How to interpolate X values from Y values? (Standard Curve)

interpolateinterpolate xpolyfitpolyvalstandard curve

I have a set of data that I fitted with a linear fit to create a standard curve and now I'm trying to interpolate unknown x-values for known y-values. I tried using polyval and I'm pretty sure I'm doing it wrong because polyval is returning two numbers instead of three for each data set I'm trying to interpolate. Also, so far I've found lots of info on how to interpolate y, but I'm not sure how to interpolate x. Any help is greatly appreciated!
My data:
x = [10, 5, 2.5, 1.25, 0.625, 0.312, 0.156,0]
y = [41564.9, 21531.9, 15086.9, 9249, 3175.9, 1781.9, 1320.9, 182.9]
p = polyfit(x,y,1)
%Data set 1
%x1 = interpolated data
y1 = [609.9, 1085.9, 2157.9]
x1 = polyval(y1,p)
%Data set 2
%x2 = interpolated data
y2 = [1308.9, 2514.9, 4797.9]
x2 = polyval(y2,p)

Best Answer

It is best to use one of the interpolation functions to do what you want.
Use interp1 here:
x = [10, 5, 2.5, 1.25, 0.625, 0.312, 0.156,0];
y = [41564.9, 21531.9, 15086.9, 9249, 3175.9, 1781.9, 1320.9, 182.9];
y2 = [1308.9, 2514.9, 4797.9];
x2 = interp1(y, x, y2, 'linear');
figure(1)
plot(x, y, '-g')
hold on
plot(x2, y2, 'bp')
hold off
grid
legend('Data', 'Interpolated Points', 'Location', 'NW')
To interpolate ‘x2’ from ‘y2’, reverse the usual (x,y) argument order, and use (y,x) instead, as I did here. The plot shows your original data as a green line, and the interpolated points as blue stars.