help with kmeans clustering
Show older comments
hello I'm working on k-means clustering algorithms I'm using the default function of matlab
when i read the documentation i found that the distance hamming used only with binary dataset
so i tried this :
B=randi([2:3],[150,7])>2;
>> idx=kmeans(B,4,'Distance','hamming');
it's so clear that B is binary but when i click on run button i obtain this error
Undefined function 'kmeans2' for input arguments of type 'struct'.
Error in kmeans (line 322)
[varargout{1:nargout}] = kmeans2(X,k, distance, emptyact,reps,start,...
any ideas about where the problem is .?
11 Comments
Star Strider
on 6 Jun 2019
Actually, ‘B’ is logical.
Your code runs for me (in R2019a) without error, producing a (150x1) double array in ‘idx’.
What is the result when you run:
whos('B')
When I run it, I get:
Name Size Bytes Class Attributes
B 150x7 1050 logical
If you get a different result, that could help define the problem.
Abdelmalek Benaimeur
on 6 Jun 2019
Star Strider
on 6 Jun 2019
O.K. My hypothesis was that you had already defined ‘B’ as a structure, and that was causing the problem.
I copied your code, pasted it to a script, and ran it without problems. I’m now out of ideas.
KSSV
on 7 Jun 2019
Which version you are using? It is running fine in 2017b. Can you tell what
which kmeans
outputs?
Abdelmalek Benaimeur
on 7 Jun 2019
Edited: Abdelmalek Benaimeur
on 7 Jun 2019
Walter Roberson
on 7 Jun 2019
Please show the output of
which -all kmeans2
Abdelmalek Benaimeur
on 7 Jun 2019
Walter Roberson
on 7 Jun 2019
Wait... the run button? What you posted for was run at the command window, not with the run button. If you are using the run button, then your B might be something different.
Put in a breakpoint at line 322 of kmeans (the call to kmeans2) and examine the variables to figure out which of them is a structure. On my system, RNGscheme shows up as a structure but none of the other variables.
Abdelmalek Benaimeur
on 7 Jun 2019
Walter Roberson
on 7 Jun 2019
dbstop if error, run, and examine the parameters being passed to the call.
Abdelmalek Benaimeur
on 11 Jun 2019
Edited: Abdelmalek Benaimeur
on 11 Jun 2019
Answers (0)
Categories
Find more on k-Means and k-Medoids Clustering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!