
How do I interpolate X values from Y values? (Standard Curve)
43 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Anastasiya Martyts
el 31 de En. de 2015
Comentada: Image Analyst
el 20 de Jun. de 2020
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)
0 comentarios
Respuesta aceptada
Star Strider
el 31 de En. de 2015
Editada: Star Strider
el 31 de En. de 2015
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 comentarios
Albert Mamani
el 31 de En. de 2020
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' values![topoprofile.svg]()
Thanks in advance
Star Strider
el 31 de En. de 2020
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.
Más respuestas (1)
Image Analyst
el 31 de En. de 2015
Editada: Image Analyst
el 31 de En. de 2015
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 comentarios
ennabih hamza
el 20 de Jun. de 2020
i want to interpolate y values from x values using interp1(y,x,y,'method') , it doesn't work
Image Analyst
el 20 de Jun. de 2020
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).
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!