When I ran the following three commands from the Statistics and Machine Learning Toolbox in the shown order, in my command window
Y = pdist(X)
Z - linkage(Y)
T = cluster(Z,'cutoff',1.2)
where X is 3042x53 matrix of type double, I get the following error (just after I execute statement 3) "Index in position 1 is invalid. Array indices must be positive integers or logical values." I then repeated these commands with a smaller X input (4x8). Same result. I believe that "cluster" wants integers for the first two columns of the Z input, (Z was produced by linkage) but the last column of Z is a distance measure and is real - so all columns of Z must be real. What am I doing wrong or misunderstanding?

 채택된 답변

Walter Johnson
Walter Johnson 2020년 1월 26일

0 개 추천

Well thanks. It's something I will be looking out for now

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 1월 24일

1 개 추천

Z = linkage(squareform(Y)) ;

댓글 수: 6

Walter Johnson
Walter Johnson 2020년 1월 24일
Thanks Walter, but when I tried this I received the same error message when I ran the cluster command.
X = rand(4,8);
Y = pdist(X);
SY = squareform(Y);
Z = linkage(SY);
T = cluster(Z, 'cutoff', 1.2)
works for me. Tested in R2019a.
What shows up when you use
which linkage
? You should see toolbox/stats/stats/linkage.m . I am wondering if perhaps you are accidentally getting the linkage() routine from Peter Corke's Robotics Toolbox.
Walter Johnson
Walter Johnson 2020년 1월 26일
Still does not work, I copied and ran your code (see below). The linkage routine looks right too. Very strange.
>> X = rand(4,8);
Y = pdist(X);
SY = squareform(Y);
Z = linkage(SY);
T = cluster(Z, 'cutoff', 1.2)
Index in position 1 is invalid. Array indices must be positive integers or logical values.
>> which linkage
C:\Program Files\MATLAB\R2019a\toolbox\stats\stats\linkage.m
>>
Walter Roberson
Walter Roberson 2020년 1월 26일
Hmmm... I just realized that you might somehow have an existing variable named cluster
Walter Johnson
Walter Johnson 2020년 1월 26일
Ha, Bingo! Thanks a lot. Did you guess this because it happens fairly often? I feel pretty dumb.
Walter Roberson
Walter Roberson 2020년 1월 26일
It does happen a fair bit, most commonly with a variable named sum .

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

질문:

2020년 1월 24일

답변:

2020년 1월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by