필터 지우기
필터 지우기

Why is it that this attempt to run a clustergram is not working?

조회 수: 3 (최근 30일)
evanma
evanma 2016년 9월 11일
댓글: evanma 2016년 9월 11일
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.

채택된 답변

Walter Roberson
Walter Roberson 2016년 9월 11일
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),
  댓글 수: 1
evanma
evanma 2016년 9월 11일
Thanks for pointing out where I was missing an argument. I had somehow not seen the missing argument, it worked when I put in @(Xi,Xj) weuc(Xi,Xj,Wgts) so that solved it (admittedly it is highly embarrassing to miss something like that as I have been running code for hours on end over the last several months but in any event thank you for helping me see what I missed).

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by