Which Interpolation function to find Y value in 2-D range
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Image Analyst
2013-11-25
编辑:Image Analyst
2013-11-25
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 个评论
Image Analyst
2013-11-25
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;
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!