Error “ Index exceeds Matrix dimensions”

坚强是说给别人听的谎言 提交于 2020-01-05 08:18:32

问题


I am trying to read an excel 2003 file which consist of 62 columns and 2000 rows and then draw 2d dendrogram from 2000 pattern of 2 categories of a data as my plot in matlab. When I run the script, it gives me the above error. I don't know why. Anybody has any idea why I have the above error?

My data is here: http://rapidshare.com/files/383549074/data.xls

Please delete the 2001 column if you want to use the data for testing.

and my code is here:

% Script file: cluster_2d_data.m

d=2000;  n1=22;  n2=40;  N=62

Data=xlsread('data.xls','A1:BJ2000');

X=Data';

R=1:2000;

C=1:2;

clustergram(X,'Pdist','euclidean','Linkage','complete','Dimension',2,...

'ROWLABELS',R,'COLUMNLABELS',C,'Dendrogram',{'color',5})

回答1:


After the xlsread statement you should get a 2000x62 double matrix Data. Then you transpose it and assign to X, so X is 62x2000 matrix. In the clustergram vectors for the properties RowLabels and ColumnLabels are supposed to match the size of your Data, but you pass a 2000-length vector as RowLabels and 2-length vector as ColumnLabels. This might cause the error.

What version of MATLAB are you using? It looks like pretty old, since you have clustergram as function, but in later versions of Bioinformatic Toolbox it was redesigned as object. In R2010a your code would generate

"ROWLABELS size does not match data"

but I'm not sure what it would be in old version.

Try to remove RowLabels and ColumnLabels, as well as other properties. Do you still get the error?



来源:https://stackoverflow.com/questions/2776510/error-index-exceeds-matrix-dimensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!