kmeans Too many input arguments.

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

 Risposta accettata

Adam Danz
Adam Danz il 27 Giu 2019
Modificato: Adam Danz il 27 Giu 2019

1 voto

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 Commenti

Thanks for your answer,some quick, dummy questions
  1. How can I rename the matlab function like kmeans,
  2. I try builtin solution but get some error, am I write it wrong
[idx,C] = builtin('kmeans', data(:,3),2)% 2 is cluster number
Cannot find builtin function 'kmeans'
Adam Danz
Adam Danz il 27 Giu 2019
Modificato: Adam Danz il 27 Giu 2019
1) How can I rename the matlab function like kmeans,
You should not rename built-in matlab function. You should rename the custom functions by changing the filename and the function's name within the file.
2) woops! I overlooked the fact that kmeans() is a toolbox function and not a built-in matlab function. Built-in functions will indicate "built-in" when calling which().
Example: which sin -all
I updated my answer to fix that mistake. I also added option #2 & #4.
Hello, thanks for your explanations, would you please bear with me, Iam really tryin your solutions but could work it yet
I tried option 1 and give me warning that I am not allowed to change kmeans name.
Option2#
I tried it and removed all unnecessary kmeans form the list, and left the most eligible one which is under statictic toolbox, but I get the error
  • Error 1: [idx,C] = kmeans(data(:,3),2)
The constructor for class 'kmeans' must return only one output value.
  • Error 2: C= kmeans(data(:,3),2)
Error using kmeans
Too many input arguments.
Here how I reve the other kmeans fromt he list
rmpath('C:\Program Files\MATLAB\R2018b\toolbox\stats\bigdata\@tall\')
rmpath('C:\Program Files\MATLAB\R2018b\toolbox\stats\bigdata')
rmpath('C:\Program Files\MATLAB\R2018b\toolbox\stats\gpu\')
I checked the what is left here is the list
which kmeans -all
Not on MATLAB path % kmeans constructor
C:\Program Files\MATLAB\R2018b\toolbox\stats\stats\kmeans.m % Shadowed
Option4#
I change the directory with
cd('C:\Program Files\MATLAB\R2018b\toolbox\stats\stats')
I still get the Too many input arguments error
Ireally appreciate your answers
Adam Danz
Adam Danz il 27 Giu 2019
Modificato: Adam Danz il 28 Giu 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?
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

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by