Which Interpolation function to find Y value in 2-D range
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to interpolate to estimate a value marked 'x1' OR 'x2' on the image linked below/attached. It's actually only a single x value, I just added x1 x2 for illustration purposes.
I have equations which define my end points at (50,50) and (180,60) but I want to find a value for x1 or x2 when the value on the horizontal axis is any value within that range i.e I give matlab a value of 80 on the x-axis and i want to find out what value it would be for its corresponding y value via interpolation.
I am unsure which interpolation function to use in MATLAB or if it can be used here.
The code for my script is very long to explain but if anyone has a pseudocode description or with the functions showing how I could achieve this then it would be very helpful.
Note:
The values here are just examples, in my code they are actually variables that change with various input
https://dl.dropboxusercontent.com/u/104069213/example.JPG
![](https://www.mathworks.com/matlabcentral/images/broken_image.png)
0 commentaires
Réponses (1)
Image Analyst
le 25 Nov 2013
Modifié(e) : Image Analyst
le 25 Nov 2013
Use polyfit and polyval - that's one way.
x = [50,180];
y = [50, 60];
coeffs = polyfit(x,y,1);
xInterpolation = 80
yInterpolation = polyval(coeffs, xInterpolation)
x = [180, 300];
y = [60, 33];
coeffs = polyfit(x,y,1);
xInterpolation2 = 240
yInterpolation2 = polyval(coeffs, xInterpolation2)
In the command window:
xInterpolation =
80
yInterpolation =
52.3076923076923
xInterpolation2 =
240
yInterpolation2 =
46.5
2 commentaires
Image Analyst
le 25 Nov 2013
Yes, of course. You can calculate the slope and use the point-slope formula for a line
slope = (y2-y1) / (x2-x1);
yFit = slope * (xfit - x1) + y1;
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!