add xy coordinates to a graph
조회 수: 48 (최근 30일)
이전 댓글 표시
hi, i have a graph like this picture, local maxmimus are shown with red points, but i also would like to show the related xy coordinates on graph by adding commands to existing code,not with data curser. please help me if you can
댓글 수: 0
채택된 답변
Image Analyst
2013년 10월 1일
Do you mean you just want to put a text label near it?
indexToLabel = 42; % or whatever.
textString = sprintf('x = %.2f, y = %.2f', x(indexToLabel), y(indexToLabel));
text(x(indexToLabel), y(indexToLabel), textString);
Adjust the x, and y as necessary in text() to move the location of the label.
댓글 수: 4
Image Analyst
2019년 8월 22일
Put \n into the string:
numPoints = 20;
x = sort(rand(1, numPoints));
y = rand(1, numPoints);
plot(x, y, 'b.-', 'MarkerSize', 25);
grid on;
[~, indexToLabel] = max(y); % label the highest point, or whatever you want.
textString = sprintf('x = %.2f\ny = %.2f', x(indexToLabel), y(indexToLabel));
text(x(indexToLabel), y(indexToLabel), textString, 'FontSize', 20, 'Color', 'r');
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!