Leading inputs must be numeric. Matlab
-
21-06-2021 - |
Frage
Im recieving an error that I dont understand using FCM.
If I set options like it mentions in the Documentation it outputs this error:
??? Error using ==> zeros
Leading inputs must be numeric.
Error in ==> fcm at 83
obj_fcn = zeros(max_iter, 1); % Array for objective function
Error in ==> fcm at 82
[centers, U, objFun] = fcm(data, 6, 'options');
If I remove the options the code runs fine, here is the full code:
[centers, U, objFun] = fcm(data, 6, 'options');
plot(data(:,1), data(:,2),'o');
maxU = max(U);
index1 = find(U(1, :) == maxU);
index2 = find(U(2, :) == maxU);
line(data(index1,1),data(index1, 2),'linestyle','none',...
'marker','*','color','g');
line(data(index2,1),data(index2, 2),'linestyle','none',...
'marker', '*','color','r');
Lösung
The problem is that fcm
expects to receive an options array, not a string. You're passing 'options'
, but instead, you should do something like this:
options(1) = 2.0;
options(2) = 100;
options(3) = 1e-5;
options(4) = 1;
[centers, U, objFun] = fcm(data, 6, options); % notice no quotes!
I'm using the default values specified in the fcm
documentation. You may change them to whatever you like.
Alternatively, the documentation specifies that if you want the default value, you can just set the option to NaN
, so feel free to do that for whatever options you want defaults for.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow