Problem with interp1 with data that occurs multiple times

조회 수: 6 (최근 30일)
Thomas Koelen . 2015년 5월 18일
댓글: Thomas Koelen . 2015년 5월 19일
I have two sets of data:
NMA =
1.0000
0.9568
0.8540
0.7553
0.6755
0.6031
0.5388
0.4828
0.4412
0.3944
0.3344
0.2973
0.2648
0.2199
0.1967
0.1715
0.1543
0.1371
0.1126
0.1019
0.0869
0.0689
0.0602
0.0433
0.0338
0.0339
0.0276
0.0253
0.0113
0.0125
0.0177
0.0139
0.0191
0.0212
0.0212
0.0307
0.0277
0.0160
0.0279
0.0506
0.0676
0.1110
0.1188
0.0995
0.1156
0.1323
0.1104
0.0528
0.0981
and
XXX =
0
0.4938
0.9875
1.4813
1.9751
2.4689
2.9626
3.4564
3.9502
4.4440
4.9377
5.4315
5.9253
6.4190
6.9128
7.4066
7.9004
8.3941
8.8879
9.3817
9.8754
10.3692
10.8630
11.3568
11.8505
12.3443
12.8381
13.3319
13.8256
14.3194
14.8132
15.3069
15.8007
16.2945
16.7883
17.2820
17.7758
18.2696
18.7634
19.2571
19.7509
20.2447
20.7384
21.2322
21.7260
22.2198
22.7135
23.2073
23.7011
I'm trying to interpolate to find the value for XXX wher NMA is equal to 0.1, but this happens multiple times and it's not showing me the first interpolated value:
I tried plotting like this:
MTF50=interp1(NMA,XXX,0.5);
MTF10=interp1(NMA,XXX,0.1);
plot([0,MTF50],[0.5,0.5],':','color','k')
plot([MTF50,MTF50],[0,0.5],':','color','k')
text(MTF50+max(XXX)/15,0.5,['mtf50 ',num2str(round(MTF50*100)/100)])
plot([0,MTF10],[0.1,0.1],':','color','k')
plot([MTF10,MTF10],[0,0.1],':','color','k')
text(MTF10+max(XXX)/15,0.1,['mtf10 ',num2str(round(MTF10*100)/100)])
for interpolating at 0.5 it still works because there is only one place where NMA "crosses" 0.5, but for 0.1 this is not the case:
this is the plot:
As you can see it doesn't show the first occasion where NMA crosses 0.1, and in the help I can't find a way to make interp1 give multiple outputs, is there a solution for this?
Kind regards
Thomas
댓글 수: 2없음 표시없음 숨기기
Ingrid 2015년 5월 18일
I do not see how this code is working as to use interp1 the vectors should be strictly monotonic increasing which is clearly not the case
I would recommend using http://www.mathworks.com/matlabcentral/fileexchange/11837-fast-and-robust-curve-intersections instead and just give as a second curve a straight horizontal line at the value of interest
Thomas Koelen 2015년 5월 19일
Thanks, this worked:)

댓글을 달려면 로그인하십시오.

카테고리

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