kmeans Too many input arguments.

7 views (last 30 days)
Zelda Grey
Zelda Grey on 27 Jun 2019
Commented: Zelda Grey on 1 Jul 2019
Hello,
I know it asked multiple times but,alas I could not find solution so I decided to ask this. Iam looking the cluste only singe column data size(1,1)
[idx,C] = kmeans(data(:,3),2)
Error using kmeans
Too many input arguments.
  1. I get all the kmeans which kmeans -all and found 4. I believe C:\Program Files\MATLAB\R2018b\toolbox\stats\stats\kmeans.m is the correct one thats produce proper result but I could not figure out how can I make it work
  2. I go to home->set path (in environment section) and move it all the way top. But Iam getting still same error
  3. I found something str = who(which('kmeans')) bout only store the first one. Even if I store the shadowed one I do not know how can I make it work
  4. How can I remove the shadowed, as I understand if one function ishadowed it is not working
Is there a way to make work the 'wanted' kmeans, in this case it is the 3rd in the lists hadowed one.
I really appreciate the all answers
Many thanks in advance
which kmeans -all
Not on MATLAB path % kmeans constructor
C:\Program Files\MATLAB\R2018b\toolbox\stats\bigdata\@tall\kmeans.m % tall method
C:\Program Files\MATLAB\R2018b\toolbox\stats\gpu\@gpuArray\kmeans.m % gpuArray method
C:\Program Files\MATLAB\R2018b\toolbox\stats\stats\kmeans.m % Shadowed
C:\Users\zgrey\Desktop\mtex-5.1.1\tools\statistic_tools\kmeans.m % Shadowed kmeans constructor

Accepted Answer

Adam Danz
Adam Danz on 27 Jun 2019
Edited: Adam Danz on 27 Jun 2019
Option 1
The best solution is to rename all of your custom kmeans() functions with unique names. Custom functions should generally have specific, unique names to avoid this problem.
Option 2
If option 1 isn't possible, try removing the conflicting functions from your path. You can see the path to the conflicting functions by using which functionName -all and then you can use rmpath() to remove the paths.
Option 3
A band-aid solution for built-in functions is to use the builtin() function which will execute the built-in function even if it is shadowed. Unfortunately kmeans() comes from a toolbox and is not built-in.
Option 4
For non built-in function that are shadowed, if you can't do options 1 or 2, you'll need to change the current directory to the directory that stores the shadowed function. Changing the cd isn't an optimal solution which is why this option is last. cd('path')
  5 Comments
Adam Danz
Adam Danz on 27 Jun 2019
Edited: Adam Danz on 28 Jun 2019
Option 1) "I tried option 1 and give me warning that I am not allowed to change kmeans name."
That option suggests changing the name of your custom function, not the matlab functions. In fact, in a comment above I reiterated that you can/should not change the name of matlab functions.
Option 2 & 4) "The constructor for class 'kmeans' must ...."
I don't know what's going on here. Does the problem persist when you add the correct path using addpath()? Does the problem persist after restarting matlab?
Zelda Grey
Zelda Grey on 1 Jul 2019
Hi, I tried option 1, and rename the mtex kmens function with something else (kmens_mtex) and the stats kmens stop being shadowed. Thank you so mcuh for your answers

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!