write indexes in a plot

25 次查看(过去 30 天)
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
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
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 中查找有关 Nonlinear Dynamics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by