how can i write the number of line?

조회 수: 3 (최근 30일)
Thar
Thar 2015년 1월 24일
답변: Image Analyst 2015년 1월 25일
Hi!
I have a 2D plot and I want to appear on each point of the graph, the number of lines corresponding to the matrix of data.
Is there any way?
Thank you!
  댓글 수: 3
Giorgos Papakonstantinou
Giorgos Papakonstantinou 2015년 1월 24일
Hi Thodoris. Can you explain a bit more your question? I don't understand which lines you want to show in the 2D plot?
Thar
Thar 2015년 1월 25일
my data are in two columns:
300 3.345
301 4.456
303 5.789
I have the plot from these data. I want to each point in the graph to write the number of line. for example, in the point (300, 3.345) to write 1.

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

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 1월 25일
Thodoris - if you want to write the row (or line) that each point corresponds to, try using the text function. Something like
figure;
data = [300 3.345
301 4.456
303 5.789];
xlim([min(data(:,1))-1,max(data(:,1))+1]);
ylim([min(data(:,2))-1,max(data(:,2))+1]);
sRows = num2str([1:size(data,1)]');
text(data(:,1),data(:,2),sRows);
The xlim and ylim are just used for illustration purposes to ensure that we can see the area we are interested in (that given by data). We then create a vector of strings, one for each row number using
sRows = num2str([1:size(data,1)]');
and then label each point in data with those strings using text.
Try the above and see what happens!

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 1월 25일
Try this:
m=[...
300 3.345
301 4.456
303 5.789]
for row = 1 : size(m, 1)
x = m(row, 1);
y = m(row, 2);
plot(x, y, 'b*', 'MarkerSize', 15);
hold on;
caption = sprintf('(%.3f, %.3f)', x, y);
text(x+0.8, y, caption, 'FontSize', 15);
end
grid on;
xlim([296, 315]);

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by