Clear Filters
Clear Filters

"too many output arguments" when using kmeans

1 view (last 30 days)
Negar
Negar on 30 Nov 2014
Edited: Star Strider on 30 Nov 2014
Hi all,
Im trying to cluster a set of data points using kmeans. but each time I receive the many output arguments error.I even tried to run the suggested example in MATLAB doc, but the same error appears: Too many output arguments. Im really wondering what the reason might be? Here is the sample code:
X = [randn(100,2)+ones(100,2);...
randn(100,2)-ones(100,2)];
opts = statset('Display','final');
[idx,ctrs] = kmeans(X,2,...
'Distance','city',...
'Replicates',5,...
'Options',opts);
plot(X(idx==1,1),X(idx==1,2),'r.','MarkerSize',12)
hold on
plot(X(idx==2,1),X(idx==2,2),'b.','MarkerSize',12)
plot(ctrs(:,1),ctrs(:,2),'kx',...
'MarkerSize',12,'LineWidth',2)
plot(ctrs(:,1),ctrs(:,2),'ko',...
'MarkerSize',12,'LineWidth',2)
legend('Cluster 1','Cluster 2','Centroids',...
'Location','NW')
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!