Why is it that this attempt to run a clustergram is not working?
3 views (last 30 days)
Show older comments
I had looked at the distance functions documenting how to make custom distance functions as shown here: http://www.mathworks.com/help/stats/pdist.html So when I implemented it, it was as shown
XX = randn(214, 66);
weuc = @(XI,XJ,W)(sqrt(bsxfun(@minus,XI,XJ).^2 * W'));
Dwgt=pdist(XX',@(Xi,Xj) weuc(Xi,Xj,Wgts));
tree = linkage(XX','average');
figure()
leafOrder = optimalleaforder(tree,Dwgt);
dendrogram(tree,0,'colorthreshold',.3,'reorder',leafOrder) ;
clo=clustergram(XX(1:214,1:66),'linkage','complete','Standardize','none','RowPDist','euclidean','ColumnPDist',@(Xi,Xj) weuc(Xi,Xj),'Cluster', 'all','RowLabels',AA(1:214))
The weights are simply set to 1 so that for a 214 x 66 matrix the weights are a 66X 1 vector with all ones for their values.
So what happens is that the clustering works for the dendrogram but not for the clustergram. Ihad looked at the Matlab documentation to make sure I was using pdist correctly but it when I run it, Matlab just says
Error using clustergram>computeDendrogram (line 1273)
Encountered error while computing hierarchical clusters: Error evaluating distance function '@(Xi,Xj)weuc(Xi,Xj)'
Is there a reason, perhaps with the syntax I used, as to why this would be the case?
Thanks for any help you can provide.
0 Comments
Accepted Answer
Walter Roberson
on 11 Sep 2016
Your weuc requires three arguments, but the code is calling it with two arguments because you have
'ColumnPDist',@(Xi,Xj) weuc(Xi,Xj),
You need to create a W argument, even if it is just
'ColumnPDist',@(Xi,Xj) weuc(Xi, Xj, 1),
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!