Why do I get this message : Error using kmeans ---X must have more rows than the number of clusters.

Hello,
When I run a collegue script, i get this error message: Error using kmeans ---X must have more rows than the number of clusters. What are my option to solve this problem?
Thank you.
Andree

 채택된 답변

How many data points do you have? And how many clusters are you attempting to create? You can't group 4 points into 5 clusters, for example.

추가 답변 (3개)

This is the code:
ab = IM1;
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,1);
nColors = 3;
[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean',...
'Replicates',nColors + 1,'display','iter');
clear ab nColors

댓글 수: 2

Size(ab,1)... is from the Color-Based Segmentation Using K-Means Clustering example that I found on MATHWORKS documentation center.

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

the value (X/K) should be integer number without fractions. for example if you have 10 objects and cluster them to 3 groups you will get 10/3 = 3.3 and this error will pop up, but if you cluster them to 2 or 5 groups there will be no problem.
You should also check if you have any missing values in your matrix

제품

태그

Community Treasure Hunt

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

Start Hunting!

Translated by