label scatter graph plot points in order in matlab

To label the scatter plot points in order, you can follow these steps:

  1. Create a scatter plot with your desired data.
main.m
x = 1:10;
y = rand(1,10);
scatter(x,y)
39 chars
4 lines
  1. Generate the cell array of labels by converting the numeric values to strings using num2str.
main.m
labels = cellstr(num2str((1:numel(x))', '(%d)'));
50 chars
2 lines
  1. Add the text labels to the scatter plot at the corresponding (x,y) points using text.
main.m
text(x, y, labels, 'VerticalAlignment','bottom', 'HorizontalAlignment','right')
80 chars
2 lines

The text function takes the x-coordinates, y-coordinates, and labels as its input arguments. The 'VerticalAlignment' and 'HorizontalAlignment' properties specify the alignment of the text labels with respect to their corresponding data points.

The end result will be a scatter plot with data points labeled in order.

gistlibby LogSnag