find intersection points of a line and a curve.

조회 수: 29 (최근 30일)
NAVNEET NAYAN
NAVNEET NAYAN 2021년 2월 20일
편집: Adam Danz 2021년 2월 20일
I am attaching here the plot. I want to get the intersection points of the horizontal red line with the curve. Also, I want to draw the vertical lines from these intersection points. How both of these tasks can be done? In case, question is not clear feel free to comment.

채택된 답변

Adam Danz
Adam Danz 2021년 2월 20일
편집: Adam Danz 2021년 2월 20일
There are several ways to get the x values at each intersection of the y-value. The simplest solution is to use the intersections() function from the file exchange (I show a similar demo in this answer, "method #2").
That function will return the (x,y) coordinates of the intersection points. Use the x values to plot vertical lines using xline().
% x is a vector of x-values at each intersection
arrayfun(@xline,x)
Or, if you're more comfortable with for-loops,
for i = 1:numel(x)
xline(x(i))
end
  댓글 수: 3
Adam Danz
Adam Danz 2021년 2월 20일
편집: Adam Danz 2021년 2월 20일
> In your demo of "method #2", X1 and Y1 must be of same size
Correct. In any demo that would be the case. (x,y) coordinates come in pairs so they must have the same number of elements.
> My X1 is a scalar and it is single whereas Y1 is of length 282
Unless I've misunderstood your question, I think you have this reversed. The horizontal line is defined by at least two x values (the end points) and 1 unique y-value which is repeated for each x value.
The horizontal line in your plot might be something like X1=[1, 280]; Y1 =[15, 15];
NAVNEET NAYAN
NAVNEET NAYAN 2021년 2월 20일
Yes you are correct. I had reversed. Thank you for solving the query and explaining it too.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by