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
采纳的回答
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!