display the x value of a graph knowing the y value

1 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2011-11-4
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 个)

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by