函数代码:
%% 画二维散点图并编号(以x升序编号)
function scatter_number(x,y,size,color,fill)
scatter(x,y,size,color,fill)
a = [x,y];
b = sortrows(a,1); %按x升序排序
hold on
for i = 1:length(x)
num = num2str(i);
text(b(i,1)+0.01,b(i,2),num,‘FontSize’,5);
end
hold on
end
调用函数:
scatter_number(Data(:,1),Data(:,2),4,‘r’,‘filled’) % 带编号的散点图
结果: