display the x value of a graph knowing the y value

2 visualizzazioni (ultimi 30 giorni)
Hi, I have a graph y(x) and I want to know when y has a value which is the correspondent value of x. How can I do it? I can't use the data cursor because I have to do it hundreds of times.
Is there a way to input the value of y and obtain the value of x?
Thanks

Risposta accettata

Walter Roberson
Walter Roberson il 4 Nov 2011
Supposing you had done
plot(x,y)
and that the value you are looking for is ProbeY (an arbitrary variable name)
[ydist, yidx] = sort(abs(y - ProbeY));
Then
x(yidx(1))
is the x for which y(x) is the closest to ProbeY.
Sometimes, though, you only want locations where y(x) is at most ProbeY
ylocs = find(ProbeY >= y);
[ydist, ylocsidx] = sort(ProbeY(ylocs)-y);
closestyidx = ylocs(ylocsidx(1));
and then x(closestyidx) is the x for which y(x) is closest to but does not exceed ProbeY.

Più risposte (0)

Categorie

Scopri di più su Networks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by