N = 30;
R = 0.4;
randn('seed',1);
d = [...
     -2-R*randn(N,1) -.5+R*randn(N,1); ...
      2+R*randn(N,1) -.5+R*randn(N,1); ...
      .5+R*randn(N,1) +.5+R*randn(N,1); ...
];

figure(1); clf; 
plot(d(:,1),d(:,2),'.b','markersize',18);
pos = get(0,'ScreenSize');
set(gcf,'position',pos);
axis([-4 4 -2 2]);
set(gca,'xticklabel',[],'yticklabel',[])
set(gca,'xtick',[],'ytick',[])
xlabel('x','fontname','times','fontsize',14); 
ylabel('y','fontname','times','fontsize',14);
disp('Hit any key to initialize cluster centers'); pause

rand('seed',1);
[f,c] = fisofast(d,rand(size(d,1),3),[],[],1); title('Fuzzy C-means');

disp('Hit any key to see the partition'); pause

figure(1); clf;
pos = get(0,'ScreenSize');
set(gcf,'position',pos);

[ds,ind] = sort(d(:,1));
subplot(221); plot(d(:,1),d(:,2),'.b','markersize',10); hold on
plot(c(:,1),c(:,2),'r+','linewidth',2,'markersize',7); hold off
axis([-4 4 -2 2])
set(gca,'xticklabel',[],'yticklabel',[])
set(gca,'xtick',[],'ytick',[])
xlabel('x','fontname','times','fontsize',14); 
ylabel('y','fontname','times','fontsize',14);

subplot(222); 
[xx,yy]=meshgrid(-4:0.05:4, -2:0.05:2);
fm1 = xx;
fg = fgrade([xx(:) yy(:)],c,2);
fm1(:) = max(fg');
surf(xx,yy,fm1)
view(332,55)
shading interp
set(gca,'xticklabel',[],'yticklabel',[])
set(gca,'xtick',[],'ytick',[])
xlabel('x','fontname','times','fontsize',14); 
ylabel('y','fontname','times','fontsize',14);
zlabel('\mu','fontname','times','fontsize',14);

ff = xx(1,:)';
for i = 1 : 3,
   ff(:,i) = max(reshape(fg(:,i),81,161))';
end;   

subplot(224); plot(xx(1,:)',ff)
axis([-4 4 0 1])
xlabel('x','fontname','times','fontsize',14);
ylabel('\mu','fontname','times','fontsize',14);
subplot(223); plot(d(:,1),f,'.','markersize',7)
axis([-4 4 0 1])
xlabel('x','fontname','times','fontsize',14);
ylabel('\mu','fontname','times','fontsize',14);

disp('Hit any key to stop ...'); pause
close(1); clc;
