Clear Filters
Clear Filters

how to name points in a plot?

80 views (last 30 days)
John
John on 10 May 2013
Commented: Sushree Patra on 8 Dec 2018
Hello,
i am interested in naming points of my plot wiht numbers. So i tried it the following way where i is the number that should describe my node.
for i=1:length(xk)
plot(xk(i),yk(i),sprintf( '#%i'))
i=i+1;
hold on
end
but it didnt work and this error occured:
--->??? Error using ==> plot
--->Error in color/linetype argument
--->Error in ==> Plotten at 51
---> plot(xk(i),yk(i),sprintf( '#%i'))
can anyone help me with that please?
with best regards, John

Accepted Answer

Stephan M. H.
Stephan M. H. on 10 May 2013
Hi John,
where you used sprint, the plot function expects as input LineSpec or 'PropertyName' followed by Propertyvalue.
I guess a direct way would be using the text function
...
plot(xk(i),yk(i))
text(xk(i),yk(i),num2str(i))
best,
Stephan
  3 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 10 May 2013
What i=i+1 is doing in your code?
John
John on 12 May 2013
thx i found the mistake...the irritation was due to strange loops^^
it works well now and the numbers arent overwritten anymore.

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 10 May 2013
Edited: Azzi Abdelmalek on 10 May 2013
for i=1:length(xk)
text(xk(i),yk(i),num2str(i))
hold on
end
  1 Comment
Sushree Patra
Sushree Patra on 8 Dec 2018
Without for loop how to provide the numbering to each point.
Means if
x1= 167*rand (50,1);
y1=302* rand (50,1);
plot(x1,y1,'b*');

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!