How do I interpolate X values from Y values? (Standard Curve)

53 次查看(过去 30 天)
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)

采纳的回答

Star Strider
Star Strider 2015-1-31
编辑:Star Strider 2015-1-31
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.
  8 个评论
Albert Mamani
Albert Mamani 2020-1-31
How could I get X values if my curve is:
x= [0 4 10 16 23 33 45 55 60 65 88 91 101];
y= [12 8 5 5 6 7 7 6 5 5 7 8 12];
xint = 0:1:101;
yinterpol =interp1(x,y,xint,'spline');
plot(x,y,'o',xint,yinterpol)
Since for a single 'y' value, correspond many 'x' valuestopoprofile.svg
Thanks in advance
Star Strider
Star Strider 2020-1-31
Choose an appropriate range of ‘x’ and ‘y’ to interpolate over for each value of ‘y’ you want to use, and reverse the first two arguments to interp1.

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2015-1-31
编辑:Image Analyst 2015-1-31
It's all explained in my demo, attached below the image.
You can see the red training data and the blue points are more, frequent "in between" interpolated points.
  4 个评论
ennabih hamza
ennabih hamza 2020-6-20
i want to interpolate y values from x values using interp1(y,x,y,'method') , it doesn't work
Image Analyst
Image Analyst 2020-6-20
ennabih, prove it. Show your code where you prove that the y values are not interpolated. By the way, interp1(y,x,y,'method') would produce an x value at a certain y value, NOT a y value. The y value is the third input, so the x value is the output (interpolated value).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by