Finding the first occurance using interp1

6 Ansichten (letzte 30 Tage)
Jason
Jason am 27 Feb. 2018
Bearbeitet: Matt J am 27 Feb. 2018
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

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Sean de Wolski
Sean de Wolski am 27 Feb. 2018
Bearbeitet: Sean de Wolski am 27 Feb. 2018
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)
  1 Kommentar
Jason
Jason am 27 Feb. 2018
Thankyou for your answer. Im sorry I can't accept both. Matt came first.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Preprocessing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by