help with kmeans clustering

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

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.
B=randi([2:3],[150,7])>2;
>> whos('B')
Name Size Bytes Class Attributes
B 150x7 1050 logical
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.
Which version you are using? It is running fine in 2017b. Can you tell what
which kmeans
outputs?
I'm using MATLAB R2018b
>> which kmeans
C:\Program Files\MATLAB\R2018b\toolbox\stats\stats\kmeans.m
Please show the output of
which -all kmeans2
which -all kmeans2
C:\Program Files\MATLAB\R2018b\toolbox\stats\stats\private\kmeans2.m % Private to stats
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.
I'm using a script that's why i said run button (green triangle button) I send the same script to some friends it works 100% on their MATLAB but mine doesn't want to run it
dbstop if error, run, and examine the parameters being passed to the call.
I found the solution of this problem
all what i did is that i pasted the function kmeans2 to the path where I'm working
and the problem is fixed

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!