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

2 views (last 30 days)
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

Answers (1)

Image Analyst
Image Analyst on 25 Nov 2013
Edited: Image Analyst on 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 Comments
P
P on 25 Nov 2013
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 on 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;

Sign in to comment.

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!