Custom Dendrogram Ordering Implementation
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Daniele
el 16 de Dic. de 2016
Comentada: Daniele
el 16 de Dic. de 2016
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 comentarios
Respuesta aceptada
Massimo Zanetti
el 16 de Dic. de 2016
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);
Más respuestas (0)
Ver también
Categorías
Más información sobre Point Cloud Processing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!