How to find indexes and intersection points and finally giving them preference.

I have a matrix like as follows:
a = [1 0 0 0 0 0 0; 1 1 0 0 0 0 0; 1 0 1 0 0 0 0; 1 1 0 1 1 0 0; 1 1 0 1 1 0 0; 1 0 1 0 0 1 1; 1 0 1 0 0 1 1]
of which i wish to create following table:
X - For each Rows index of cols having 1;
Y - For each cols index of rows having 1;
Z - Intersection set
Further Ranking is to be done on comparing columns X and Z in such a manner that with minimum of elements in both columns, maximum of common elements should be there and each time that common element should be emitted from the whole X column for further comparison so that again with minimum of elements in both sets max common elements can be found.
For ranking some logic can be applied like for each set of X and Z, union can be applied wherein when on combining two sets no element is added, then its given rank 1 and soon one element is added to a set, then rank increases to 2 and so on.
Please help.

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 24 de Mzo. de 2014
Editada: Andrei Bobrov el 25 de Mzo. de 2014
EDIT
f = @(x){x};
[ii,jj] = find(a & a');
z = accumarray(jj,ii,[],f);
[i1,j1] = find(a);
x = accumarray(i1,j1,[],f);
y = accumarray(j1,i1,[],f);
r = cellfun(@(x,y)numel(setdiff(x,y))+1,x,z,'un',0);
out = [x(:),y(:),z(:),r(:)];

4 comentarios

@Andrei Bobrov - Sir, the code works very well till z column. But ranks are not coming as required. I had thought of one logic ie on getting the difference of x and z set, as the number of remaining elements increase, the rank also increases. Hope it can be incorporated in some way ? Though the concept is that we select the set having minimum of elements and then compare with z column to have max of common elements and give ranks accordingly.
Hi Neeraj!
I am corrected my code.
Neeraj Bhanot
Neeraj Bhanot el 26 de Mzo. de 2014
Editada: Neeraj Bhanot el 26 de Mzo. de 2014
@Andrei Bobrov - Thanks alot sir. It worked very well.
Neeraj Bhanot
Neeraj Bhanot el 26 de Mzo. de 2014
Editada: Neeraj Bhanot el 26 de Mzo. de 2014
@Andrei Bobrov - Sir, when i applied this code to my another problems it did not return the same solution required. i have mailed the .m file at your id mentioned here. Please look into it and help.
Thanks.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 24 de Mzo. de 2014

Editada:

el 26 de Mzo. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by