Vertical Distance between two points of curves on a graph

7 vues (au cours des 30 derniers jours)
charles atlas
charles atlas le 15 Juil 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
  1 commentaire
Sean de Wolski
Sean de Wolski le 15 Juil 2011
What data or functions were used to plot the graphs?

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 15 Juil 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));

Plus de réponses (0)

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by