Drawing Lines on a Graph

7 ビュー (過去 30 日間)
Andrew Kay
Andrew Kay 2018 年 12 月 13 日
回答済み: Star Strider 2018 年 12 月 13 日
I have two intersecting graphs plotted on the same axis,
ie: plot(V,P1,V,P2)
where P1 and P2 are variations of the same function
I would like to have a line drawn vertically to the x axis, and horizonally to the y axis from the point where these two lines intersect
How would I complete such a command?
Thanks

回答 (2 件)

Mark Sherstan
Mark Sherstan 2018 年 12 月 13 日
編集済み: Mark Sherstan 2018 年 12 月 13 日
Find the intersection points with the polyxpoly function and then use the line function to draw your desired line. If you need further help please post your data.

Star Strider
Star Strider 2018 年 12 月 13 日
If you do not have the Mapping Toolbox, this will likely work:
V = linspace(0, 30); % Arbitrary Vector
Pfcn = @(a,t) a(1).*exp(t/10) + a(2); % Arbitrary Function
P1 = Pfcn([ 4.2, -42],V); % Evaluate Function
P2 = Pfcn([-4.2, 4.2],V); % Evaluate Function
xint = interp1((P1-P2), V, 0); % Find ‘x’ At Intersection
yint = interp1(V,P1, xint); % Find ‘y’ At Intersection
figure
plot(V,P1,V,P2) % Plot Functions
hold on
xl = xlim;
yl = ylim;
plot(xint*[1 1], yl, 'g', xl, yint*[1 1],'g') % Plot Lines
hold off

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by