Borrar filtros
Borrar filtros

Deleting similar rows in Matrices contained in cell

2 visualizaciones (últimos 30 días)
Rinachi Garg
Rinachi Garg el 31 de Mayo de 2012
If I have a set of [ 'a' 'b' 'c' 'd'],and I want different and non repetitive combinations of 2, I get matrix A. In matrix B I store the elements which are not present in Matrix A which I find using setdiff. Now, I want to divide these four elements 'a', 'b' 'c' 'd' into sets of two and that should be non repetitive. But, in the case below: ad cd is repeating as it is similar to cd ab, similarly, ac bd is same as bd ac.
I have two matrices in a cell: A = [ ab; ac; ad; bc; bd; cd ] and B = [cd; bd; bc; ad; ac; ab ]; So, is there any function in MATLAB which can help me eliminate repetitive partition cases? I looked into unique function but that did not help.

Respuestas (1)

Kye Taylor
Kye Taylor el 31 de Mayo de 2012
If I understand your objective, try the following
arrayOfElements = ['a','b','c','d']; % your initial array
indicesOfUniquePairs = nchoosek(1:length(arrayOfElements),2);
arrayOfUniquePairs = arrayOfElements(indicesOfUniquePairs);
It's a beautiful thing.
  1 comentario
Rinachi Garg
Rinachi Garg el 1 de Jun. de 2012
nchoosek is really cool.
Actually my question was: As can be seen in the above matrix :
ab(from Matrix A) corresponds to cd in Matrix B. and cd from Matrix A corresponds to ab in Matrix B. So I consider that this case is being repeated so I want to delete such cases and get the final output:
A = [ab; ac; ad] and B = [cd; bd; bc];
There is always an option of writing a tedious code. But, I was looking for a way which can do it faster. Because here I am giving simple examples but I may have large number of arrays to compare with many more elements.

Iniciar sesión para comentar.

Categorías

Más información sobre Numeric Types en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by