Which Interpolation function to find Y value in 2-D range

3 次查看(过去 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

回答(1 个)

Image Analyst
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 个评论
P
P 2013-11-25
I've actually decided to use the formula for linear interpolation and just code it into my script as a function. Is this the same formula?
Image Analyst
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 CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by