write indexes in a plot

조회 수: 21 (최근 30일)
Luis Isaac
Luis Isaac 2020년 2월 21일
댓글: Giuseppe Inghilterra 2020년 2월 21일
Dear
I have a matrix P with n rows and two columns, each of the column store the x and y position of a particle.
Represent the particle postions is easy (plot(P(:,1),P:,2)), I would like to write the index of each particle just beside each point
How can I do it?
Many thanks!!

채택된 답변

Giuseppe Inghilterra
Giuseppe Inghilterra 2020년 2월 21일
Hi,
Example code taken from above answer:
x = 1:10; y = 1:10; scatter(x,y);
a = [1:10]'; b = num2str(a); c = cellstr(b);
dx = 0.1; dy = 0.1; % displacement so the text does not overlay the data points
text(x+dx, y+dy, c);
This should resolve your problem.
  댓글 수: 2
Luis Isaac
Luis Isaac 2020년 2월 21일
yes, this is what I am looking for
But a final question, Is there any way to control the size of the numerical labels of each point?
Giuseppe Inghilterra
Giuseppe Inghilterra 2020년 2월 21일
You can specify fontsize property as follow:
text(x+dx, y+dy, c,'FontSize',k);
with k as scalar value equal to your desired fontsize.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by