所以为了继续我刚才的问题,有了这个建议的程序:
%// Input
A =[
2 1 5
1 3 10
1 -2 5
0 5 25
5 0 25
1 1 2
-1 -1 2]
[unqcol3,unqidx,allidx] = unique(A(:,3),'stable')
counts = sum(bsxfun(@eq,A(:,3),unqcol3.'),1) %//'
out =[A(unqidx,:) counts(:)]
scatter(out(:,3), out(:,4))因此,它将生成一个数组和一个类似于这样的图:
a b d counts
2 1 5 2
1 3 10 1
0 5 25 2
1 1 2 2D与计数

但是我想把(a,b)作为每个散点点上的标签,所以这是我想要的图:

因此,当您看到相应的a,b将自动标记在每个散点点上,请帮助谢谢。
发布于 2015-02-21 19:35:20
我会使用sprintf和一个简单的for循环来完成它。
完整代码:
clear
clc
A =[
2 1 5
1 3 10
1 -2 5
0 5 25
5 0 25
1 1 2
-1 -1 2]
[unqcol3,unqidx,allidx] = unique(A(:,3),'stable');
counts = sum(bsxfun(@eq,A(:,3),unqcol3.'),1);
out =[A(unqidx,:) counts(:)]
scatter(out(:,3), out(:,4));
%// This step is not necessary but its easier to understand using it.
a = out(:,1);
b = out(:,2);
x = out(:,3);
y = out(:,4);
for k = 1:size(out,1)
T{k} = sprintf('%i%i',a(k),b(k))
end
%// Determine x- and y-shift to place text relative to the scatter point
xshift = 0.03; yshift = 0.03;
%// Place the text
text(x+xshift, y+yshift, T);输出:

发布于 2015-02-21 19:40:17
在你有了out之后,你可以使用这个no-loop approach -
%// Plot points and set x-y limits
scatter(out(:,3), out(:,4),'o')
xlim([0 30]), ylim([0 2.5])
%// Create string labels
L = cellstr(strcat(strtrim(num2str(out(:,1))),strtrim(num2str(out(:,2)))))
%// Set some y-shift and put text labels
y_shift = 0.1
text(out(:,3),out(:,4)+y_shift,L)
set(gca,'YGrid','on')代码运行-

https://stackoverflow.com/questions/28650118
复制相似问题