2016-03-06 34 views

回答

1

您可以使用text(x, y, txt);将文本添加到图形的特定点。

查看Add Text to Specific Points on Graphhere了解更多信息。

更新1

如果希望每个形心有一个特定的文本,你将不得不指定长度的单元阵列等于质心的数量(STR的长度= K):

str = {'text1','text2', 'text3'}; 
plot(C(:,1),C(:,2),'square','Color','k','MarkerSize', 20); 
text(C(:,1),C(:,2),str); 

在这个例子中有K = 3的平均值。

更新2

可以按如下方式发起使用一个循环的str数组:

X = cell(K,1); 
for ii=1:numel(X) 
    X{ii} = ii; % Or you can use any other information related to the coordinates. 
end 
+0

TXT1 = '1'; TXT(质心(:,1),质心(:,2),TXT1);但它不起作用。 –

+0

它是'text()'而不是'txt()'。 – vsimkus

+0

它的工作,但无法检测到正确的质心,我有txt1 ='1',为群集一和txt2 ='2'为群集二:情节(质心(:,1),质心(:,2),' square','Color','k','MarkerSize',20);文本(tmp_x(:,1),tmp_x(:,2),, TXT1); –