필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
P
P 2013년 11월 25일
댓글: Image Analyst 2013년 11월 25일
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