MATLAB: Label index/variable name near data points

label;points

Hello I,m looking for solution to print a index near to data point:
The example values are:
M =
2278 2 685 2
197 2 2221 2
524 2 2496 2
1061 2 3415 2
651 2 5810 2
1105 2 3817 2
276 2 4527 2
I want to have a text box near to (2278,2) 1; (197,2) 2 …..
lables = 1 %lables = (1:k)
figure('Name','Result','NumberTitle','on');
hold on
p11 = plot(M(:,2),M(:,1),'ro','Color','g');
hold on
p12 = plot(M(:,4),M(:,3),'rx','Color','r');
text(M(:,4),M(:,3),labels,'VerticalAlignment','bottom','HorizontalAlignment','right')
xlabel('tube dimension')
ylabel('Results')
tube_size_help = sprintf('%.0f',tube_size);
nameX=strcat(name ,'_tube_size_',tube_size_help);
saveas(gcf, [nameX '_results.png'])
But I get everythere the same value. Hov can I insert a changing index of row near to M(row,2),M(row,1) (or names of measures)
for loop? Or somethink better?
Thank you!

Best Answer

This is easy with labelpoints() found on the file exchange.
figure('Name','Result','NumberTitle','on');
hold on
p11 = plot(M(:,2),M(:,1),'ro','Color','g');
hold on
p12 = plot(M(:,4),M(:,3),'rx','Color','r');
labelpoints(M(:,4),M(:,3), 1:size(M,1), 'E', 0.2)
% "E" means "east" of the coordinate
% 0.2 is a buffer space between the label and the marker
Related Question