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.
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

采纳的回答

Matt J
Matt J 2018-2-27
编辑:Matt J 2018-2-27
Use only the first two data X,Y data points in the interpolation.
  6 个评论
Torsten
Torsten 2018-2-27
It could happen that Y is increasing, couldn't it ?
Matt J
Matt J 2018-2-27
编辑:Matt J 2018-2-27
Not according to the posted figure, but even if it could, I think the extension is an exercise I'll leave for the OP.

请先登录,再进行评论。

更多回答(1 个)

Sean de Wolski
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 CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by