Problem with Interp1

1 次查看(过去 30 天)
Jason
Jason 2018-1-26
Hi, I cannot get interp1 to give me the correct answer. I have a simple, data set (see below) and all I want to do if use interpolation to give me the x value at y=thresh
thresh=225.5
My code is:
vq1 = interp1(x,y,thresh,'pchip')
This results in vq1=12207908.76
x=
1.00
2.00
3.00
4.00
5.00
6.00
7.00
8.00
9.00
10.00
11.00
12.00
13.00
14.00
15.00
16.00
17.00
18.00
19.00
20.00
21.00
22.00
23.00
24.00
25.00
26.00
27.00
28.00
29.00
30.00
31.00
32.00
33.00
34.00
35.00
36.00
37.00
38.00
39.00
40.00
41.00
42.00
y=
430.00
422.00
445.00
438.00
423.00
435.00
432.00
422.00
419.00
440.00
403.00
427.00
444.00
437.00
429.00
417.00
440.00
441.00
432.00
425.00
413.00
370.00
271.00
139.00
63.00
28.00
36.00
27.00
25.00
27.00
15.00
27.00
22.00
29.00
20.00
19.00
27.00
17.00
17.00
15.00
22.00
17.00

采纳的回答

Star Strider
Star Strider 2018-1-26
If you want to find the ‘x’-values where ‘y’ equals ‘thresh’, you need to reverse the order of ‘x’ and ‘y’ in the interp1 call. However with your data, you first have to find the approximate index of that value, since you cannot simply reverse the order of the entire vector.
Try this:
yval = find(y >= thresh, 1, 'last'); % Define Region To Interpolate
vq1 = interp1(y(yval-1:yval+1), x(yval-1:yval+1), thresh,'pchip') % Interpolate In Region
vq1 =
23.3818
  2 个评论
Jason
Jason 2018-1-26
Thankyou (and to Stephen)
Star Strider
Star Strider 2018-1-26
As always, my pleasure.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by