Finding the first occurance using interp1
7 ビュー (過去 30 日間)
古いコメントを表示
Hello. I have some data (red curve) and I'm trying to find the X value at which Y = 0.2.

I have used
Y20 = interp1(Y,X,0.2,'linear')
which works well, but finds the last occurrance.
How can I find the first occurrance (i.e. around x=9)
Thanks
0 件のコメント
採用された回答
その他の回答 (1 件)
Sean de Wolski
2018 年 2 月 27 日
編集済み: Sean de Wolski
2018 年 2 月 27 日
Use cummax and cummin to find the the first set of points that cross 0.2. Then interp just them.
x = 1:10
y = sin(x)
plot(x,y)
yval = 0.2;
idx = find(cummin(y)<0.2 & cummax(y)>0.2, 1, 'first')
interp1(y([idx-1 idx]), x([idx-1, idx]), 0.2)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!