Vertical Distance between two points of curves on a graph
조회 수: 6 (최근 30일)
이전 댓글 표시
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
채택된 답변
Walter Roberson
2011년 7월 15일
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));
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!