label points in order in matlab

To label points in order in Matlab, you can use the text function along with the num2str function to convert the numeric labels into strings.

Here's an example code:

main.m
% create some random 2D points
x = rand(1,10);
y = rand(1,10);

% create a variable for the labels
labels = 1:length(x);

% plot the points
scatter(x,y)

% loop over the labels and add them to the plot
for i=1:length(labels)
    % add a label using the text function
    text(x(i), y(i), num2str(labels(i)), 'HorizontalAlignment', 'center')
end
345 chars
16 lines

This will create a scatter plot of the points with the labels added in order. The text function takes the x and y coordinates of the point as the first two arguments, the label as the third argument, and the horizontal and vertical alignment as the following arguments.

gistlibby LogSnag