Vertical Distance between two points of curves on a graph

6 views (last 30 days)
I have a graph with two curves written in matlab and I want code or a simple command to display the maximum vertical distance between the two curves on the graph. And, if possible I would like to also calculate the minimum vertical distance between the two points on the graph as well and display it on the graph.
Any help is much appreciated. V/R, Charles Atlas

Accepted Answer

Walter Roberson
Walter Roberson on 15 Jul 2011
lines = findobj(gcf, 'type', 'line');
CurveHandle1 = lines(1);
CurveHandle2 = lines(2);
x1 = get(CurveHandle1, 'XData');
y1 = get(CurveHandle1, 'YData');
x2 = get(CurveHandle2, 'XData');
y2 = get(CurveHandle2, 'YData');
projectedy2 = interp1(x2,y2,x1);
[maxdist,maxidx] = max(abs(projectedy2-y2));
[mindist,minidx] = min(abs(projectedy2-y2));
fprintf(1,'Maximum vertical distance is %g at x=%g\n', maxdist, x1(maxidx));
fprintf(1,'Minimum vertical distance is %g at x=%g\n', mindist, x1(minidx));

More Answers (0)

Categories

Find more on Networks in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!