"Cris Luengo" <cris.luengo@google.for.my.name.to.contact.me> wrote in message <i5nncn$k6h$1@fred.mathworks.com>...
> "Ömer KAYA" <e170531@metu.edu.tr> wrote in message <i5niu7$g6$1@fred.mathworks.com>...
> > " mshahrashoub shahrashoub" <shahrashoub@yahoo.com> wrote in message <i5la7d$m4g$1@fred.mathworks.com>...
> > > Hi,
> > >
> > > Does anybody have an idea about, How can I cluster or segmentation, my vectorized data.
> > >
> > > Example : Data = [1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4] ;
> > >
> > > and I want to make 4 cluster. How can make it ?
> > >
> > >
> > > I have Matlab R2010a with Image Processing toolbox.
> > >
> > > Thanks in advance
> >
> > Hello;
> >
> > A=0;
> > B=0;
> > C=0;
> > D=0;
> > %% defining the for loop matrix
> > [f,Matrix] = size(Data);
> > clear f;
> > %% Defining the loop
> > for i= 1 :4;
> > for j=1 : Matrix;
> > if Data(1,j)== 1 ; %the cluster Mid Point (can calculate on avarage)
> > A(1,j) = Data(1,j);
> > elseif Data(1,j) == 2; %Second Cluster
> > B(1,j)=Data(1,j);
> > elseif Data(1,j) == 3; %Third
> > C(1,j)=Data(1,j);
> > elseif Data(1,j) == 4; %Forth Cluster
> > D(1,j)=Data(1,j);
> > end
> > end
> > end
> > %%
> > use this code and you will separate in in clusters but the problem is i couldn't make the process start from the beginning...
> >
> > so the last cluster is the same size of the input data; there should be another person can figure out how to deal with the rest.
> >
> > Regads
> >
> > Ömer KAYA
> >
> > Middle East Technical Universty
>
> Ömer, your code does the same as:
> A = (Data==1)*1;
> B = (Data==2)*2;
> C = (Data==3)*3;
> D = (Data==4)*4;
> but I cannot imagine that this is what the original poster wants.
>
> mshahrashoub, what is it that you want as output?
>
> Cheers,
> Cris.
Thanks everybody for helps.
The code written by Ömer works fine with given example. But the problem is, my data set not like this :
For example :
If I have a vector like :
X = [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 22 44 1 1 ]
To assess 4 cluster for given vector how this could work. In addition of this Chris you define A = 1 , B = 2 , C =3, D =4 But How can algorithm recognize this numbers. System should be robust. I think I need to use density to to calculate A,B,C,D numbers.
What about this code:
How it is works :
DataM = [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 22 44 1 1 ] % vector example
I am trying to make 4 cluster
%%
So first of all i am dividing vector to number of cluster
Size of vector : 20 Cluster size : 4
Each cluster will have 5 values.
%Sequentially I am adding the numbers amount of cluster
DataM = 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 23 67 68 69
then dividing sum of cluster with number of elements in cluster
DataM = 15/5 15/5 15/5 328/5
DataM = 3 3 3 65
After this I can divide it more(simplification ) but this results is enough for me.
Now I got 4 cluster values
%%
> > > a=0;
> > > i = 0;
> > > L = size(DataM,1);
> > > for i=0:i+4:L; %% "L" is a size of the vector
> > > a = a+1; %% "a" is a size of cluster
> > > valmatrix = zeros(L/a,1); %% Create empty matrix to calculate cumulative of the cluster
> > > valmatrix(i+1 )=DataM(i+1 ,x,y); %% start the first element with first element of the vector Example 1 1 1 1 to 1 2 3 4 5 : First digit should be same
> > > for z = 2+i:i+4,
> > > valmatrix(z)=valmatrix((z) 1) + DataM(z,x,y); % calculate rest of the cumulative
> > > end
> > > valmatrix = sum(valmatrix) / (L/a);
> > > Output(a ,x,y) = valmatrix ;
> > > end
Output should be DataM = 3 3 3 65 something like this.
I dont know this code should work probably
Thanks in advance
