add xy coordinates to a graph
33 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
maryam
am 1 Okt. 2013
Kommentiert: Image Analyst
am 22 Aug. 2019
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150225/image.jpeg)
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 Kommentare
Akzeptierte Antwort
Image Analyst
am 1 Okt. 2013
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 Kommentare
Image Analyst
am 22 Aug. 2019
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');
![0001 Screenshot.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/235017/0001%20Screenshot.png)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Title finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!