display the x value of a graph knowing the y value
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Walter Roberson
on 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 Comments
More Answers (0)
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!