필터 지우기
필터 지우기

get the intersection points in the graph

조회 수: 3 (최근 30일)
Elysi Cochin
Elysi Cochin 2018년 1월 19일
편집: Elysi Cochin 2018년 1월 20일
if i draw a line at y = 1,
how to get the point at which the line will intersect the graph (marked in blue line in the image)?
Also i need to find the area of the region.

채택된 답변

Star Strider
Star Strider 2018년 1월 19일
Try this:
x = [1,2,3,4,6,7,9,12,14,15,17,18,19];
y = [0,2,4,5,7,9,10,8.5,6,4,2,1.5,0];
yline = 1;
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector(y);
idx = zci(y - yline); % Indices Near ‘y=1’
for k1 = 1:numel(idx)
xint(k1) = interp1(y(idx(k1):idx(k1)+1),x(idx(k1):idx(k1)+1),yline,'linear','extrap'); % Find ‘x’ At ‘y=1’
end
RegionArea = trapz(x,y-yline)
figure(1)
plot(x, y)
hold on
plot(x, ones(size(x))*yline)
plot(xint, ones(size(xint))*yline, 'pg', 'MarkerSize',10)
hold off
legend('Data', 'y = 1', 'Intersection Points', 'Location','NE')
text(6, 4, sprintf('Area = %.2f', RegionArea))

추가 답변 (1개)

Jan
Jan 2018년 1월 19일
I have answered this question today already. Please read your other thread: https://www.mathworks.com/matlabcentral/answers/377903-draw-a-line-parallel-to-x-axis#answer_300827.
Why did you remove the diagram there and inserted it here again?

카테고리

Help CenterFile Exchange에서 Directed Graphs에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by