2017-04-13 80 views
0

我试过以下链接(不幸的是,没有工作): Associated Labels in a dendrogram plot - MATLAB 而不是站ID,我的将PDBId。如何在Matlab中使用函数树状图(树,名称,值)将标签放入树状图中?

我的问题: 我创建从一个CSV文件树状图 “similarity_nogrp.csv”

PDBId \t 0 \t   1 \t   2   3 \t    4 \t  
 
1A06 \t 1 \t   0.05344457 \t 0.439285476 \t 0.46664877 \t 0.40868216 \t 
 
1B6C \t 0.05344457 \t 1 \t   0.03371103 \t 0.029899324 \t 0.033972369 
 
1BO1 \t 0.439285476 \t 0.03371103 \t 1 \t   0.5579095 \t 0.488785068 \t 
 
1CDK \t 0.46664877 \t 0.029899324 \t 0.5579095 \t 1 \t   0.50682912 \t 
 
1CJA \t 0.40868216 \t 0.033972369 \t 0.488785068 \t 0.50682912 \t 1 \t 
 
1CSN \t 0.490366809 \t 0.047467331 \t 0.50842029 \t 0.533638473 \t 0.465180315 
 
1E8X \t 0.036246998 \t 0.002009194 \t 0.057903016 \t 0.066882369 \t 0.058359239 \t
这里,在第一线,

PDBID是排Id,

0 1 2 3 4是列号,

我要标注叶节点按PDBID,但我从第2列读取CSV文件(仅适用于数字,离开PDBIds),后来虽然在树状图设置“标签”为“PDBID”()我得到的错误:

这里是我的代码:

filename = 'D:\\matlab codes\\similarity_nogrp.csv' 
 
X = csvread(filename,1,1) 
 
Z = linkage(X,'average') 
 
C = cluster(Z, 'maxclust', 3) 
 
H = dendrogram(Z,'Orientation','left','Labels',filename.PDBId)

的最后一行的错误是:

??? Attempt to reference field of non-structure array.
请为我提供一种方法,使我可以使用PDBId作为叶节点的标签。 在此先感谢。

回答

1

所以,你的问题是你试图访问一个filename的结构字段,但filename是一个字符数组,而不是一个结构。另外,readcsv只能读取数字值,因此无论如何它都不会获得标签。

您可以使用readtable来获取行名和列名,然后从表中读取行名。下面是我使用的代码:

filename = 'D:\\matlab codes\\similarity_nogrp.csv'; 
T = tableread(filename,'ReadVariableNames', true, 'ReadRowNames', true) 
X = T{:,:}; % Get the data from the table without row/col names 
Z = linkage(X,'average') 
C = cluster(Z, 'maxclust', 3) 
H = dendrogram(Z,'Orientation','left','Labels',T.Properties.RowNames) 

结果我得到了: Results

+0

谢谢@Matthew – user3701435