# Vertical Distance between two points of curves on a graph

13 views (last 30 days)
charles atlas on 15 Jul 2011
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
Sean de Wolski on 15 Jul 2011
What data or functions were used to plot the graphs?

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));
Sean de Wolski on 15 Jul 2011
wow, +1.