Custom Dendrogram Ordering Implementation
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi,I'm trying to implement a custom ordering of a dendrogram (obtained using the linkage function) based on the rule that the "highest" branch has to be always on the right side. As an example:
%generate a tree using linkage
rng('default'); %for reproducibility
X = rand(10,2);
D = pdist(X);
tree = linkage(D,'average');
%my desired order
myOrd = [1,4,5,8,9,2,10,3,6,7];
%plot
figure();
subplot(2,1,1);
dendrogram(tree);
title('Default leaf order');
subplot(2,1,2);
dendrogram(tree,'Reorder',myOrd);
title('Desired leaf order');
Do you have any idea for a more efficient implementation?
Thank you
댓글 수: 0
채택된 답변
Massimo Zanetti
2016년 12월 16일
Apparently, none of the available functionalities of optimalleaforder does the work. So here it is a function that runs through the rows of the tree matrix generated by linkage and produces your output.
function c = binOrd(tree)
p = size(tree,1);
c = zeros(1,p+1);
k = 0;
recBin(p);
function recBin(r)
x = tree(r,1:2)-p-1;
if x(1)<=0
c(k+1) = tree(r,1);
k = k+1;
else
recBin(x(1));
end
if x(2)<=0
c(k+1) = tree(r,2);
k = k+1;
else
recBin(x(2));
end
end
end
To get your desired rightmost binary ordering, run dendogram with 'Reorder' set as the output of the binOrd function:
tree = linkage(D,'average');
myBinOrder = binOrd(tree);
dendrogram(tree,'Reorder',myBinOrder);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Point Cloud Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!