give name to node in dendrogramm
조회 수: 24 (최근 30일)
이전 댓글 표시
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156988/image.jpeg)
hi guys! I need to rename number-node on the right side of this dendrogramm, how I can do that? tnx!
댓글 수: 0
채택된 답변
Massimo Zanetti
2016년 10월 8일
Use the 'Labels' property of the dendogram plot. Keep in mind that dendrogram labels any leaves in the dendrogram plot containing a single data point with that data point's label.
For example, assume you have a dendogram with 5 leaves, create a cell that lists {'label 1', 'label 2',...,'label 5'}, and set this cell as argument of 'Labels' property. This will assign 'label 1' to leaf 1, ..., 'label n' to leaf n.
X = rand(5,2);
Y = pdist(X);
Z = linkage(Y,'average');
%create cell of labels
labels = cellstr(num2str((1:size(X,1))', 'label %d'))
%plot dendogram with custom labels
h=dendrogram(Z, 0, 'Labels', labels, 'orientation', 'left');
댓글 수: 0
추가 답변 (1개)
Kelly Kearney
2016년 10월 7일
The answer will depend on whether you're showing all the leaves of the dendrogram or not. If yes, then the 'Labels' input will do the trick:
X = rand(50,2);
Y = pdist(X,'cityblock');
Z = linkage(Y,'average');
labels = cellstr(num2str((1:size(X,1))', 'test%d'));
dendrogram(Z, 0, 'Labels', labels, 'orientation', 'left');
If you're truncating the leaves (second input >0 and <size(X,1)), things get a little more complicated, since the above only labels single-node leaves. I've done it, but would have to dig around for the code... so comment if you need that.
댓글 수: 1
Ben
2022년 10월 12일
Hi Kelly, I'm trying to get the x-axis labels to work with truncated leaves - do you have the code to share? I realise this is a very old thread!
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!