Problem with Interp1
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
Star Strider
le 26 Jan 2018
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!