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

 채택된 답변

Image Analyst
Image Analyst 2013년 10월 1일

0 개 추천

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

maryam
maryam 2013년 10월 1일
편집: maryam 2013년 10월 1일
tnx for ur answer, please help me more! i used ur code as below:
[pks,locs]=findpeaks(r,'minpeakdistance',5,'THRESHOLD',100);% finding max
indexToLabel=[pks,locs];
textString = sprintf('x = %.2f, y = %.2f', x(indexToLabel), y(indexToLabel));
text(x(indexToLabel), y(indexToLabel), textString);
this error appeared on screen: Subscript indices must either be real positive integers or logicals.
i couldn't understand the meaning of that :-(
could u plz explain what should i do?
Image Analyst
Image Analyst 2013년 10월 1일
You need to get the x,y coordinates. Plus you have an array whereas I had just a single index (42). You can put it in a loop over indexToLabel where you call text once for each peak location.
Sean Haines
Sean Haines 2019년 8월 22일
how would you add a \r to this label?
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

질문:

2013년 10월 1일

댓글:

2019년 8월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by