필터 지우기
필터 지우기

How should I find the x value of the given y value?

조회 수: 47 (최근 30일)
Laura Kim
Laura Kim 2020년 7월 18일
답변: Star Strider 2020년 7월 18일
Hi, I have this graph and here I would like to find the coordinates where the horizontal line and curvy graph meet together
How should I find the x-coordinate of the given y-value (this case y=6.585)?
Thank you

답변 (2개)

SAA
SAA 2020년 7월 18일
편집: SAA 2020년 7월 18일
I am not sure if you can find an exact value since you are trying to compare 2 doubles and that's usually not a good idea, but you can get it using a tolerance.
it should be something like this:
% assuming you have 2 matrices x and y containing your data
z = x(y==6.585); % assuming that there is an exact value that equals it but most likely you don't so you need a tolerance
% this should work
tol = 10^-9;
z = x(abs(y-6.585) < tol); % you can also use find instead of x

Star Strider
Star Strider 2020년 7월 18일
Try something like this:
y = 6.585;
eqidx = find(diff(sign(curvy_graph - y)));
for k = 1:numel(eqidx)
ixrng = [-1 0]+eqidx(k);
xval(k) = interp1(curvy_graph(ixrng), x(ixrng), y);
end
That will give you the x-value for all of the intersections. Choose the ones you want to use. See the documentation on interp1 for its options.
.

카테고리

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