display the x value of a graph knowing the y value
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
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.
0 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!