Finding the first occurance using interp1
조회 수: 9 (최근 30일)
이전 댓글 표시
Hello. I have some data (red curve) and I'm trying to find the X value at which Y = 0.2.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/170812/image.png)
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에서 Multirate Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!