0

How do you output the data from each cluster using FCM in matlab?

[center,U,obj_fcn] = fcm(data,cluster_n) 
G Gr
  • 6,030
  • 20
  • 91
  • 184

2 Answers2

1

I used the U vector to determine which class each datapoint belongs to. It content can be thought of as the probability for each class to belong to a class (notice then all columns sum to 1), so choosing which ever class is most probable is a reasonable approach. This is done by storing the second output argument of max().

Below I have stated some general purpose code you can use.

%# Start parameters and variables
nClasses = 3;
CM = jet(nClasses); %# Colormap for visualization of up to 255 classes

%# Create dataset
data = [mvnrnd([0 0],eye(2),100); mvnrnd([3,3],0.5*eye(2),50)];

%# Cluster
[center,U,obj_fcn] = fcm(data,nClasses); 

%# Extract class assignment
[~,y] = max(U); 

%# Visualize
f1=figure(1);clf
plot(data(:,1),data(:,2),'.k')
hold on
for i = 1 : nClasses
    plot(data(y==i,1),data(y==i,2),'o','color',CM(i,:));
end

enter image description here

EDIT:

To extract the datapoints of one class into a new variable, simply use

class1data = data(y==1,:);
Vidar
  • 4,141
  • 5
  • 24
  • 30
  • Vidar I dont think that this is what im looking for, I want each cluster to be in a seperate dataset, `[~,y] = max(U);` just out puts 1x1000 (in my example) which is just the sample dataset I originally used. – G Gr Jul 18 '12 at 18:57
  • Okey. I have edited my solution. For the future, please post what you are looking for a bit clearer :) – Vidar Jul 18 '12 at 19:07
-4

My dataset contain 900rows with 4 attribute. Now I oredi cluster it in 9 cluster in each attribute. How I going to code in matlab so that it will show out all data in every cluster? Now I am only get center,U, obj_func only.

THE data I get is for me to calculate the standard deviation. So i need all the in every cluster.

user229044
  • 232,980
  • 40
  • 330
  • 338