Labeling points in order in a plot
I have开发者_开发百科 two vectors representing the location of points (x,y) that I'd like to plot.
I know how to plot them, but I'd also like to label them 1, 2, 3, 4... with labels visible on the plot. The labels represent their order in the vector.
Here's one way to do this:
p = rand(10,2);
labels = cellstr( num2str([1:10]') ); %' # labels correspond to their order
plot(p(:,1), p(:,2), 'rx')
text(p(:,1), p(:,2), labels, 'VerticalAlignment','bottom', ...
'HorizontalAlignment','right')
精彩评论